-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·55 lines (45 loc) · 1.33 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
// Creates a hot reloading development environment
const path = require('path');
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const DashboardPlugin = require('webpack-dashboard/plugin');
const config = require('./webpack.config.development');
const app = express();
const compiler = webpack(config);
// Apply CLI dashboard for your webpack dev server
compiler.apply(new DashboardPlugin());
const host = process.env.HOST || 'localhost';
const port = process.env.PORT || 4002;
function log() {
arguments[0] = '\nWebpack: ' + arguments[0];
console.log.apply(console, arguments);
}
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
stats: {
assets: false,
colors: true,
version: false,
hash: false,
timings: false,
chunks: false,
chunkModules: false,
children: false
},
historyApiFallback: true
}));
app.use(webpackHotMiddleware(compiler));
app.use(express.static('dist'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, './src/index.html'));
});
app.listen(port, host, (err) => {
if (err) {
log(err);
return;
}
log('🚧 App is listening at http://%s:%s', host, port);
});