forked from styled-components/styled-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevServer.js
More file actions
48 lines (40 loc) 路 1.06 KB
/
Copy pathdevServer.js
File metadata and controls
48 lines (40 loc) 路 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const path = require('path')
const exec = require('child_process').exec
const Express = require('express')
const watch = require('node-watch')
const srcPath = __dirname.split('/example')[0] + '/src';
const hotBuild = () => exec('npm run build:dist', (err, stdout, stderr) => {
if (err) throw err
if (stdout) {
console.log(`npm run build:dist --- ${stdout}`)
}
if (stderr) {
console.log(`npm run build:dist --- ${stderr}`)
}
})
watch(srcPath, (filename) => {
console.log(`${filename} file has changed`)
hotBuild()
})
const app = new Express()
const port = 3000
app.use(Express.static('dist'))
app.get('/with-perf.html', (req, res) => {
res.sendFile(path.join(__dirname, 'with-perf.html'))
})
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'))
})
app.listen(port, error => {
/* eslint-disable no-console */
if (error) {
console.error(error)
} else {
console.info(
'馃寧 Listening on port %s. Open up http://localhost:%s/ in your browser.',
port,
port
)
}
/* eslint-enable no-console */
})