123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #!/usr/bin/env node
- // 设置环境变量以抑制各种警告
- process.env.NODE_ENV = 'development';
- process.env.SASS_SILENCE_DEPRECATIONS = '*';
- process.env.NODE_OPTIONS = '--no-deprecation --no-warnings --disable-warning=ExperimentalWarning';
- process.env.NPM_CONFIG_AUDIT = 'false';
- process.env.NPM_CONFIG_FUND = 'false';
- process.env.DISABLE_OPENCOLLECTIVE = 'true';
- process.env.SUPPRESS_NO_CONFIG_WARNING = 'true';
- process.env.CI = 'true';
- const { spawn } = require('child_process');
- const path = require('path');
- // 找到 webpack-cli 的真实路径
- const webpackCliPath = require.resolve('webpack-cli/bin/cli.js');
- // 设置 Node.js 内存限制和优化参数
- const nodeArgs = [
- '--max-old-space-size=8192', // 8GB 内存限制
- '--gc-interval=100', // 更频繁的垃圾回收
- webpackCliPath, // <--- 修改这里:直接使用JS文件的绝对路径
- 'serve',
- '--config',
- path.resolve(__dirname, '../webpack.config.js'),
- '--mode',
- 'development'
- ];
- // // 设置 Node.js 内存限制和优化参数
- // const nodeArgs = [
- // '--max-old-space-size=8192', // 8GB 内存限制
- // '--gc-interval=100', // 更频繁的垃圾回收
- // path.resolve(__dirname, '../node_modules/.bin/webpack'),
- // 'serve',
- // '--config',
- // path.resolve(__dirname, '../webpack.config.js'),
- // '--mode',
- // 'development'
- // ];
- console.log('🚀 启动开发服务器...');
- console.log('💾 内存限制: 8GB');
- console.log('⚡ 启用内存优化模式');
- const child = spawn('node', nodeArgs, {
- stdio: ['inherit', 'pipe', 'pipe'],
- env: {
- ...process.env,
- NODE_ENV: 'development',
- NODE_OPTIONS: '--max-old-space-size=8192'
- }
- });
- // 处理输出,过滤不必要的信息
- child.stdout.on('data', (data) => {
- const output = data.toString();
-
- // 过滤掉Babel和其他不必要的提示
- const shouldFilter = [
- '[BABEL] Note:',
- 'code generator has deoptimised',
- 'exceeds the max of',
- 'Deprecation Warning',
- 'WARNING in',
- 'export \'',
- 'was not found in'
- ].some(warning => output.includes(warning));
-
- if (shouldFilter) {
- return; // 直接忽略这些输出
- }
-
- // 显示重要信息
- if (output.includes('webpack compiled') ||
- output.includes('Local:') ||
- output.includes('Network:') ||
- output.includes('webpack://') ||
- output.includes('ERROR') ||
- output.includes('ready') ||
- output.includes('Project is running') ||
- output.includes('webpack-dev-server')) {
- process.stdout.write(output);
- }
- });
- child.stderr.on('data', (data) => {
- const output = data.toString();
- // 过滤掉各种类型的警告
- const shouldFilter = [
- 'Deprecation',
- 'experiment',
- 'warning',
- 'WARNING in',
- '@import rules are deprecated',
- 'More info and automated migrator',
- 'sass-lang.com/d/import',
- 'Global built-in functions are deprecated',
- 'Use meta.inspect instead',
- 'Use string.slice instead',
- 'Use string.index instead',
- 'Use color.mix instead',
- 'export \'', // 模块导出警告
- 'Invalid deprecation', // 无效的弃用警告
- 'Module Warning (from ./node_modules/sass-loader',
- '[BABEL] Note:', // Babel提示
- 'code generator has deoptimised', // Babel代码生成提示
- 'exceeds the max of', // 文件大小提示
- 'was not found in' // 导出未找到警告
- ].some(warning => output.includes(warning));
-
- if (!shouldFilter) {
- process.stderr.write(output);
- }
- });
- child.on('close', (code) => {
- console.log(`开发服务器退出,代码: ${code}`);
- });
- child.on('error', (error) => {
- console.error('❌ 启动失败:', error.message);
- console.log('\n🔧 请尝试手动运行: npm run dev:simple');
- });
- // 处理进程退出
- process.on('SIGINT', () => {
- console.log('\n正在关闭开发服务器...');
- child.kill('SIGINT');
- });
- process.on('SIGTERM', () => {
- child.kill('SIGTERM');
- });
|