-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.js
More file actions
41 lines (35 loc) · 1.01 KB
/
dev-server.js
File metadata and controls
41 lines (35 loc) · 1.01 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
const path = require('path')
, express = require('express')
, webpack = require('webpack')
, webpackDevMiddleware = require('webpack-dev-middleware')
, webpackHotMiddleware = require('webpack-hot-middleware')
, development = require('./build.js').development
, config = require(`./config/webpack.config.${development ? 'development' : 'production'}`)
, app = express()
, compiler = webpack(config)
, host = 'localhost'
, port = 3000;
function log() {
arguments[0] = '\nWebpack: ' + arguments[0];
console.log.apply(console, arguments);
}
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
stats: {
colors: true
},
historyApiFallback: true,
hot: true
}));
app.use(webpackHotMiddleware(compiler));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(port, host, (err) => {
if (err) {
log(err);
return;
}
log('🚧 App is listening at http://%s:%s', host, port);
});