dev-server.js
1.3 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
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const webpack = require('webpack');
const compression = require('compression');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackConfig = require('./webpack.dev.config.js');
const path = require('path');
const compiler = webpack(webpackConfig);
const devMiddleware = webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
logLevel: 'silent',
stats: 'none',
headers: {
'Access-Control-Allow-Origin': '*'
}
});
const hotMiddleware = webpackHotMiddleware(compiler, {
log: () => {}
});
const app = express();
app.use(devMiddleware);
app.use(hotMiddleware);
app.use((req, res, next) => {
res.set('Access-Control-Allow-Origin', '*');
next();
});
app.use('/',
express.static(path.join(__dirname, '../')),
express.static(path.join(__dirname, './bundle/')),
express.static(path.join(__dirname, './dll/')));
app.use('/event', (req, res) => {
if (req.query.action === 'reload') {
hotMiddleware.publish({
action: 'reload'
});
}
res.json({
action: req.query.action,
message: 'ok'
});
});
app.use(compression());
app.listen(5001, () => {
console.log('dev start 5001');
});