-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
49 lines (39 loc) · 1.33 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
var fs = require('fs');
var express = require('express');
var app = express();
var webpack = require('webpack');
var SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
var webpackDevMiddleware = require('webpack-dev-middleware');
var config = require('./webpack.config.js');
var compiler = webpack(config);
var webpackDevMiddlewareParam = {
// options
publicPath: '/dist',
noInfo: false,
quiet: false,
stats: {
chunks: false,
colors: true,
child: true
}
};
var webpackDevMiddlewareInstance = webpackDevMiddleware(compiler, webpackDevMiddlewareParam);
app.use(webpackDevMiddlewareInstance); // 应用针对 express 框架的 webpack 调试中间件
app.listen(3000, function(){
console.log('server listen on 3000');
});
var once = true;
// 主页入口
app.get('/', function(req, res) {
// 应用单入口插件
res.send('hello~');
});
// 新增入口
app.get('/add', function(req, res) {
// 应用单入口插件
console.log('apply SingleEntryPlugin');
compiler.apply(new SingleEntryPlugin(process.cwd(), './src/index2.js','index2'));
once && webpackDevMiddlewareInstance.invalidate(); // 强制重新构建一次,不用调用多次,后续的触发由 webpack 自己 hot reload
once = false; // 置 once 就是 false
res.send('already apply SingleEntryPlugin');
});