-
Notifications
You must be signed in to change notification settings - Fork 16
/
agent.js
26 lines (26 loc) · 1004 Bytes
/
agent.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
'use strict';
const utils = require('./lib/utils');
const WebpackServer = require('./lib/server');
const MultProcessWebpackServer = require('./lib/mult-process-server');
module.exports = agent => {
agent.messenger.on('egg-ready', () => {
const config = agent.config.webpack;
agent.messenger.setMaxListeners(config.maxListeners || 10000);
// 兼容 Node 前端渲染只有一个 webpack 配置
if (config.webpackConfigList && !Array.isArray(config.webpackConfigList)) {
config.webpackConfigList = [config.webpackConfigList];
}
// webpack-tool not need proxy again
const pluginConfig = Object.assign({}, config, { proxy: false });
if (utils.isUseMultProcess(agent.baseDir, config)) {
new MultProcessWebpackServer(agent, pluginConfig).start();
} else {
const port = utils.getPort(config.port);
pluginConfig.port = port;
new WebpackServer(agent, pluginConfig).start();
}
});
process.on('exit', () => {
process.exit(0);
});
};