From fad3c95a9263a03f4d6b13217d2975f23a04f5ff Mon Sep 17 00:00:00 2001 From: winixt Date: Wed, 20 Nov 2024 20:47:09 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=20webpack=20dev=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=20&=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20ctrl=20+=20c=20=E7=BB=93=E6=9D=9F=E8=BF=9B=E7=A8=8B=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/commands/dev/devServer.js | 16 ++++++++++++---- packages/fes/src/cli.js | 11 +++++------ packages/fes/src/utils/fork.js | 6 ++++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/fes-builder-webpack/src/plugins/commands/dev/devServer.js b/packages/fes-builder-webpack/src/plugins/commands/dev/devServer.js index e48263be..79ba5b2a 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/dev/devServer.js +++ b/packages/fes-builder-webpack/src/plugins/commands/dev/devServer.js @@ -1,6 +1,6 @@ -import WebpackDevServer from 'webpack-dev-server'; -import webpack from 'webpack'; import { chalk } from '@fesjs/utils'; +import webpack from 'webpack'; +import WebpackDevServer from 'webpack-dev-server'; export function startDevServer({ webpackConfig, host, port, proxy, https, beforeMiddlewares, afterMiddlewares, customerDevServerConfig }) { const options = { @@ -31,8 +31,16 @@ export function startDevServer({ webpackConfig, host, port, proxy, https, before }; const compiler = webpack(webpackConfig); const server = new WebpackDevServer(options, compiler); - - console.log(chalk.green('Server: '), chalk.blue(`${options.server}://${options.host}:${options.port}`)); + if (options.host === '0.0.0.0') { + // eslint-disable-next-line no-console + console.log(chalk.green(' ➜ Local: '), chalk.cyan(`${options.server}://127.0.0.1:${options.port}`)); + // eslint-disable-next-line no-console + console.log(chalk.gray(' ➜ Network: '), chalk.gray(`${options.server}://${options.host}:${options.port}`)); + } + else { + // eslint-disable-next-line no-console + console.log(chalk.green(' ➜ :Local: '), chalk.cyan(`${options.server}://${options.host}:${options.port}`)); + } server.startCallback((err) => { if (err) { console.error(err); diff --git a/packages/fes/src/cli.js b/packages/fes/src/cli.js index a9ac21e6..08dda6f4 100644 --- a/packages/fes/src/cli.js +++ b/packages/fes/src/cli.js @@ -1,17 +1,16 @@ import process from 'node:process'; import { chalk, semver, yParser } from '@fesjs/utils'; import fesPkg from '../package.json'; +import { hackFesInBuild } from './hackFesInBuild'; import { Service } from './serviceWithBuiltIn'; import fork from './utils/fork'; import getCwd from './utils/getCwd'; import getPkg from './utils/getPkg'; -import { hackFesInBuild } from './hackFesInBuild'; const requiredVersion = fesPkg.engines.node; function checkNodeVersion(wanted, id) { if (!semver.satisfies(process.version, wanted, { includePrerelease: true })) { - // eslint-disable-next-line no-console console.log(chalk.red(`You are using Node ${process.version}, but this version of ${id} requires Node ${wanted}.\nPlease upgrade your Node version.`)); process.exit(1); } @@ -29,21 +28,21 @@ const args = yParser(rawArgv); const child = fork({ scriptPath: require.resolve('./forkedDev'), }); - // ref: // http://nodejs.cn/api/process/signal_events.html process.on('SIGINT', () => { child.kill('SIGINT'); - process.exit(1); + process.exit(); }); process.on('SIGTERM', () => { child.kill('SIGTERM'); - process.exit(1); + process.exit(); }); } else { hackFesInBuild(); - if (command === 'build') + if (command === 'build') { process.env.NODE_ENV = 'production'; + } await new Service({ cwd: getCwd(), diff --git a/packages/fes/src/utils/fork.js b/packages/fes/src/utils/fork.js index 2ec85bc8..dfaaca09 100644 --- a/packages/fes/src/utils/fork.js +++ b/packages/fes/src/utils/fork.js @@ -21,8 +21,9 @@ export default function start({ scriptPath }) { catch (e) { port = 9230; // node default inspect port plus 1. } - if (usedPorts.includes(port)) + if (usedPorts.includes(port)) { port += 1; + } usedPorts.push(port); return `--inspect-brk=${port}`; @@ -31,8 +32,9 @@ export default function start({ scriptPath }) { } // set port to env when current port has value - if (CURRENT_PORT) + if (CURRENT_PORT) { process.env.PORT = CURRENT_PORT; + } const child = fork(scriptPath, process.argv.slice(2), { execArgv,