-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevServer.js
35 lines (32 loc) · 944 Bytes
/
devServer.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
const express = require('express')
const port = 3000
const path = require('path')
const app = express()
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const webpackConfig = require('./webpack.dev.config.js')
const compiler = webpack(webpackConfig)
const middleware = webpackDevMiddleware(compiler, {
hot: true,
filename: 'bundle.js',
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
chunks: false
},
historyApiFallback: true
})
app.use(middleware)
app.use(webpackHotMiddleware(compiler, {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000
}))
app.get('*', function response (req, res) {
res.write(middleware.fileSystem.readFileSync(path.join(__dirname, 'build/index.html')))
res.end()
})
app.listen(port, function () {
console.log('Listening at port: ', port)
})