在windows上部署时,多个命令行窗口影响测试和客户部署操作,而且不够美观、简洁
分别在下面两个位置添加上这个参数:windowsHide 可以达到隐藏 npm start 时打开的多个窗口,
forkAgentWorker() {
this.agentStartTime = Date.now();
const args = [ JSON.stringify(this.options) ];
const opt = {
windowsHide: true
};
2.
```
//cfork\index.js
/**
* fork worker with certain settings
*/
function forkWorker(settings) {
if (settings) {
settings.windowsHide = true;
cluster.settings = settings;
cluster.setupMaster();
} else {
cluster.setupMaster({ windowsHide: true });
}
return cluster.fork(attachedEnv);
}
// config/config.default.js
// 通过配置cluster的windowsHide属性达到隐藏/显示 npm start 时打开的多个窗口
config.cluster = {
windowsHide: true,
};

Node 9.4.0 新增了原生的支持,然而这个参数不起作用(至少在我的 Win10 上不起作用)。这个参数稳定了,就方便了。
fork 好像是不支持的,只有 spwan 等才有
api上有这一段 child_process.fork() 方法是 child_process.spawn()的一个特例
我的理解是fork是从spawn上封装的,如果没有特意屏蔽额外参数,这个参数是可以传过去的
child_process.fork() 方法是 child_process.spawn()。我在本机实验是有效的

你试试启动命令直接传递 --windows-hide 看看,应该可以传递进去的
const opt = {};
// add debug execArgv
const debugPort = process.env.EGG_AGENT_DEBUG_PORT || 5800;
if (this.options.isDebug) opt.execArgv = process.execArgv.concat([ --${semver.gte(process.version, '8.0.0') ? 'inspect' : 'debug'}-port=${debugPort} ]);
const agentWorker = childprocess.fork(this.getAgentWorkerFile(), args, opt);
根据这段代码可以看出,参数并没有传递到想要的位置。
我还原了修改之后,加上参数启动,窗口还是打开了
@atian25
1.
fork 好像是不支持的,只有 spwan 等才有
fork的options参数最终会传递给spwan的options参数,没有对特殊字段进行处理,所以fork也支持这个windowsHide参数,文档里没写。
https://github.com/nodejs/node/blob/master/lib/child_process.js
2.
你试试启动命令直接传递 --windows-hide 看看,应该可以传递进去的
--windows-hide 方式的参数在 args 这个对象上 https://github.com/eggjs/egg-cluster/blob/d424239e56fec96d9e9c29e9bb1d96a46acc97b5/lib/master.js#L215,fork的options参数没有这个值
3.
cfork目前没有支持windowsHide这个参数,所以可能也需要支持一下。cluster组件已经支持了这个参数。
https://nodejs.org/dist/latest-v12.x/docs/api/cluster.html#cluster_cluster_settings
@qingdengyue
厉害厉害
欢迎提 PR
@atian25 修改好了,看看这样实现行不行~ :smile:
Most helpful comment
@atian25
1.
fork的options参数最终会传递给spwan的options参数,没有对特殊字段进行处理,所以fork也支持这个windowsHide参数,文档里没写。
https://github.com/nodejs/node/blob/master/lib/child_process.js
2.
--windows-hide 方式的参数在 args 这个对象上 https://github.com/eggjs/egg-cluster/blob/d424239e56fec96d9e9c29e9bb1d96a46acc97b5/lib/master.js#L215,fork的options参数没有这个值
3.
cfork目前没有支持windowsHide这个参数,所以可能也需要支持一下。cluster组件已经支持了这个参数。
https://nodejs.org/dist/latest-v12.x/docs/api/cluster.html#cluster_cluster_settings