-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (37 loc) · 989 Bytes
/
server.js
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
const path = require('path')
const express = require('express')
const webpack = require('webpack')
const webpackHotMiddleware = require('webpack-hot-middleware')
const webpackMiddleware = require('webpack-dev-middleware')
const webpackConfig = require('./webpack.config.js')
const PORT = 3000
const HOSTNAME = '0.0.0.0'
const app = express()
const compiler = webpack(webpackConfig)
const middleware = webpackMiddleware(compiler, {
contentBase: 'src',
publicPath: webpackConfig.output.publicPath,
stats: {
chunks: false,
chunkModules: false,
colors: true,
hash: false,
modules: false,
timings: true,
},
})
app.use(middleware)
// HMR
app.use(webpackHotMiddleware(compiler))
app.get('*', (req, res) => {
res.write(
middleware.fileSystem.readFileSync(path.join(__dirname, 'dist/index.html'))
)
res.end()
})
app.listen(PORT, HOSTNAME, err => {
if (err) {
console.error(err)
}
console.info(`Listening on http://${HOSTNAME}:${PORT}`)
})