@xins/devtool
Version:
官方·前端二次开发脚手架库
77 lines (60 loc) • 2.05 kB
JavaScript
;
const path = require('path')
const spawn = require('cross-spawn');
// 此处获取参数 - 开始
const shellConf = Object.fromEntries(process.argv.slice(2).map(item => item.split('=')))
// console.log('--shellConf--', shellConf)
process.env.XINS_ENTRY = shellConf.entry || 'index'
process.env.XINS_MODE = shellConf.mode || 'base'
process.env.XINS_ENV = shellConf.env || ''
process.env.XINS_GZIP = shellConf.gzip || 'on'
process.env.XINS_NPMLINK = shellConf.npmlink || 'off'
// 此处获取参数 - 结束
const command = process.argv[2] || 'start'
process.env.PORT = shellConf.port || '8000'
process.on('unhandledRejection', error => {
throw error;
});
const runShell = () => {
const result = spawn.sync(
'node',
[
path.resolve(__dirname, `../scripts/${command}.js`),
...process.argv.slice(3),
],
{ stdio: 'inherit' }
);
if (result && result.signal) {
if (result.signal === 'SIGKILL') {
console.log(
'The build failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if (result.signal === 'SIGTERM') {
console.log(
'The build failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
process.exit(1);
}
if(result.status !== 0) {
process.exit(result.status);
}
return result
}
runShell()
// const Webpack = require('webpack');
// const WebpackDevServer = require('webpack-dev-server');
// const webpackConfig = require('../config/webpack.dev.conf.js');
// const compiler = Webpack(webpackConfig);
// const devServerOptions = { ...webpackConfig.devServer, open: true };
// const server = new WebpackDevServer(devServerOptions, compiler);
// const runServer = async () => {
// console.log('Starting server...');
// await server.start();
// };
// runServer();