UNPKG

@wbi/cli-service

Version:

local service for wb-cli projects

46 lines (42 loc) 1.28 kB
/** * Created by Administrator on 2019/2/10. * 开发服务器主进程 * 用于管理构建配置被修改时,重启子进程(dev-server.js) */ const path = require('path') const cp = require('child_process') const utils = require('./utils') const wbConfig = utils.wbConfig let initStart = true // 是否首次启动 function start () { const child = cp.fork(path.join(__dirname, './dev-server.js')) // 子进程消息事件监听 child.on('message', function (event) { switch (event.action) { case 'open': // 首次启动,自动打开浏览器 if (initStart) { initStart = false wbConfig.private.open && require('open')('http://localhost:' + event.port) } else { // 非首次启动,需向子进程发送消息。 // 可能是浏览器显示弹窗信息:正在重启服务... // 需主动刷新浏览器 // child.send('reload'); } break case 'restart': child.kill('SIGINT') start() break } }) } module.exports = function () { // 开启构建服务子进程 if (!process.send) { start() } // 开启组件管理子进程 cp.fork(utils.resolve('../componentServer/server/app.js'), [process.cwd()]) }