mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-05 03:05:07 +08:00
chore: 优化 webpack dev 日志输出 & 优化 ctrl + c 结束进程的日志输出
This commit is contained in:
parent
9d8692e5f8
commit
fad3c95a92
@ -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);
|
||||
|
@ -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(),
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user