在 Electron 应用程序中运行多个 nodejs 服务器

时间:2021-07-13 17:17:19

标签: node.js electron electron-builder

我正在使用 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",
 
  }
}

0 个答案:

没有答案