Skip to content

Commit f4ffc2c

Browse files
author
sky
committed
fix: child process running port had used
1 parent 2be33df commit f4ffc2c

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

lib/child-process.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ process.on('message', m => {
99
const baseDir = m.baseDir;
1010
const target = m.target;
1111
const webpackConfig = utils.getWebpackConfig(config, { baseDir, target });
12-
const EASY_ENV_DEV_PORT = process.env.EASY_ENV_DEV_PORT;
13-
const webPort = Number(EASY_ENV_DEV_PORT || m.port);
14-
const nodePort = Number(EASY_ENV_DEV_PORT || m.port) + 1;
12+
const webPort = utils.getPort(m.port);
13+
const nodePort = webPort + 1;
1514
const port = target === 'web' ? webPort : nodePort;
1615
const webpackTool = new WebpackTool({ port });
1716
compiler = webpackTool.createWebpackCompiler(webpackConfig, () => {

lib/utils.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ const path = require('path');
33
const fs = require('fs');
44
const IMG_REGEX = /\.(png|jpe?g|gif|svg)(\?.*)?$/;
55
const PKG_PREFIX = '@easy-team';
6+
7+
exports.getPkgInfo = baseDir => {
8+
const pkgFile = path.join(baseDir || process.cwd(), 'package.json');
9+
if (fs.existsSync(pkgFile)) {
10+
return require(pkgFile);
11+
}
12+
return {};
13+
};
14+
615
exports.readWebpackMemoryFile = (compiler, filePath) => {
716
const compilerList = Array.isArray(compiler) ? compiler : [compiler];
817
for (let i = 0; i < compilerList.length; i++) {
@@ -131,6 +140,10 @@ exports.normalizeProxyUrlFile = (app, url) => {
131140
return path.join(app.baseDir, url);
132141
};
133142

143+
// fix child process running mutil count
134144
exports.getPort = port => {
135-
return Number(process.env.EASY_ENV_DEV_PORT || port);
136-
};
145+
const pkgInfo = exports.getPkgInfo();
146+
const name = pkgInfo.name || 'webpack-project';
147+
const EASY_ENV_DEV_PORT = `EASY_ENV_DEV_PORT_${name}`;
148+
return Number(process.env[EASY_ENV_DEV_PORT] || port);
149+
};

0 commit comments

Comments
 (0)