UNPKG

app-lib-cli-plugin-server

Version:

app-lib-cli-plugin-server

42 lines (36 loc) 1.54 kB
/************************************************************************************************** * es dev * * 依赖 * * html-webpack-plugin * * webpack * * webpack-cli * * webpack-dev-server * * ************************************************************************************************* */ // 具体执行可插件化 const start = async (args, opt, _opts) => { let { log, exec, nodeUtils: { getBin, getCanUsePort, isSysUsePort, readline }, utils: { optionsToArray, getStaticPath } } = _opts; let { option } = args; let port = 1 * option.port; // 文件配置路径 let configPath = getStaticPath(`${opt.commond}.${opt.options[0]}.webpack.${option.model ? (option.model + ".") : ''}config.js`); // TODO 追加自定义部分 let binPath = getBin('webpack-dev-server'); let isUse = await isSysUsePort(port); if (isUse) { let canUsePort = await getCanUsePort(port + 1); log.mwn(`[${port}] port is EADDRINUSE, use [${canUsePort}]?`); let isNewPort = await readline('yes/no', 'yes'); if (isNewPort === 'y' || isNewPort == 'yes') { port = canUsePort; } else { return log.mwn('npm init', `give up use port [${canUsePort}]`) } } option.port = port; exec(binPath, ['--config', configPath].concat(optionsToArray(option, ['target', 'model'])), { stdio: 'inherit' }) return 0; // 非0 返回则为有异常 } module.exports = start