forked from anorudes/redux-easy-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-dev-server.js
36 lines (27 loc) · 967 Bytes
/
webpack-dev-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
import Express from 'express';
import http from 'http';
const app = new Express();
const server = new http.Server(app);
const port = 3001;
const proxy = require('http-proxy').createProxyServer({});
global.ssr = true;
(function initWebpack() {
const webpack = require('webpack');
const webpackConfig = require('./webpack/common.config');
const compiler = webpack(webpackConfig);
// Proxy for static folder
app.use(/\/static\/(.*)/, (req, res) => {
req.url = req.originalUrl;
proxy.web(req, res, { target: 'http://localhost:3000' });
});
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true, publicPath: webpackConfig.output.publicPath,
}));
app.use(require('webpack-hot-middleware')(compiler, {
log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000,
}));
}());
server.listen(port, () => {
const host = server.address().address;
console.log('Server is listening on http://%s:%s', host, port);
});