-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
36 lines (31 loc) · 1011 Bytes
/
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
const express = require('express');
const connectHistoryApiFallback = require('connect-history-api-fallback');
const webpackDevMiddleware = require('webpack-dev-middleware');
const config = require('./webpack.common.js');
const webpack = require('webpack');
const webpackHotMiddleware = require('webpack-hot-middleware');
const app = new express();
// 监听端口
const port = 3000;
app.use('/', connectHistoryApiFallback());
app.use('/', express.static('dist'));
app.use('/static', express.static('static'));
if (process.env.NODE_ENV !== 'production') {
const compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true
},
lazy: false,
watchOptions: {
aggregateTimeout: 300,
poll: true
}
}));
// 热更新
app.use(webpackHotMiddleware(compiler));
}
app.listen(port, () => {
console.log(`app listening on port ${port}!\n`);
});