-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevServer.js
39 lines (32 loc) · 1.01 KB
/
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
let path = require('path');
let config = require('./config/config.js');
let chalk = require('chalk');
let express = require('express');
let webpack = require('webpack');
let webpackConfig = require('./scripts/webpack.dev');
let webpackDevMiddleware = require('webpack-dev-middleware');
let webpackHotMiddleware = require('webpack-hot-middleware');
let compiler = webpack(webpackConfig);
let app = express();
app.use(express.static(path.join(__dirname, '/')));
//服务器中间件
app.use(webpackDevMiddleware(compiler,{
noInfo: true,
stats: {
colors: true,
},
publicPath: webpackConfig.output.publicPath,
watchOptions: {
aggregateTimeout: 300,
poll: true
}
}));
//热更新
app.use(webpackHotMiddleware(compiler));
app.set('port', parseInt(config.dev.port));
app.listen(app.get('port'),function(err){
if (err) {
console.log(chalk.red(err));
}
console.log(chalk.green('App is running at http://localhost:' + app.get('port') + ', please wait to build --->>>'));
})