forked from jch254/starter-pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devServer.js
39 lines (31 loc) · 1018 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
36
37
38
39
import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import express from 'express';
import path from 'path';
import http from 'http';
import webpackConfig from './webpack.config.babel';
const app = express();
const WEBPACK_PORT = 3001;
const compiler = webpack(webpackConfig);
app.use(webpackMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false,
},
}));
app.use(webpackHotMiddleware(compiler));
// This is necessary to handle URL correctly since client uses Browser History
app.get('*', (request, response) => response.sendFile(path.resolve(__dirname, '', './dist/index.html')));
app.listen(WEBPACK_PORT, 'localhost', (err) => {
if (err) {
console.log(err);
}
console.log(`WebpackDevServer listening at localhost:${WEBPACK_PORT}`);
});
http.createServer(app);