node.js - 在 Electron 应用程序中运行多个 nodejs 服务器
问题描述
我正在使用electron-builder
为 macOS 打包 dmg 文件。但我需要同时运行两个 nodeJS 服务器。第一个效果很好,我像主文件一样使用它。但是第二个有问题,我尝试使用childProc.spawn(process.execPath, [path.join('path/to/server.js')])
. 当我调整此命令时,它会在我运行它时创建两个应用程序, electron .
但是当我尝试使用此命令打包应用程序时,electron-builder
会在启动时运行两个应用程序,然后关闭第二个应用程序(这是我产生的)。
如何在一个应用程序中运行两台服务器?
这是我的electron-builder.json
:
{
"appId": "com.myApp.app",
"productName": "myApp",
"directories": {
"app": ".",
"output": "out",
"buildResources": "build-res"
},
"files": [
...,
"second-server-folder",
],
"mac": {
"category": "public.app-category.utilities",
"target": ["dmg"]
},
"dmg": {
"background": null,
"backgroundColor": "#ffffff",
"window": {
"width": "400",
"height": "300"
},
"contents": [
{
"x": 100,
"y": 100
},
{
"x": 300,
"y": 100,
"type": "link",
"path": "/Applications"
}
]
}
}
以及来自主文件的代码示例,我如何尝试运行第二台服务器:
childProc.spawn(process.execPath, ['path/to/server.js'])
以及`packge.json`的样本
{
"name": "myApp",
"version": "0.02.1",
"private": true,
"main": "bin/www",
"scripts": {
"start-electron": "electron .",
"pack": "electron-builder build",
"rebuild": "electron-rebuild",
},
"devDependencies": {
"electron-rebuild": "^2.3.5",
"electron": "^13.1.6",
"electron-builder": "^22.10.5",
}
}
解决方案
推荐阅读
- c# - 如何将键值对添加到 deedle 系列?
- javascript - 元素在 JavaScript 中没有任何命令就消失了
- javascript - Eleventy(11ty)可以有父子集合吗?
- node.js - 聚合物 cli 缺少装饰器插件
- batch-file - 批量移动文件并浏览子文件夹
- event-handling - UML 用例图
- arrays - 在一系列单元格上使用 ISFORMULA 和 ARRAYFORMULA
- c++ - Opencv无法在图像上画线
- qt - 如何将QCustomPlot的轴与QWidget的原始边缘之间的距离设置为0?
- docker - Docker - 在构建期间在主机上运行命令