使用电子生成器从电子应用程序构建独立的 .exe

Kir*_*iya 5 windows macos installation electron electron-builder

我正在使用电子 v6.0.9 和电子构建器 v21.2.0。这是我的package.json用于生产构建的打包配置。

"build": {
    "appId": "com.app.prototype",
    "productName": "Pluto",
    "copyright": "Copyright © 2018 Simon Inc.",
    "mac": {
      "target": [
        "zip"
      ]
    },
    "win": {
      "publisherName": "Simon Inc.",
      "target": [
        "nsis",
        "zip"
      ]
    },
    "linux": {
      "target": [
        "AppImage",
        "tar.gz"
      ]
    },
    "dmg": {
      "icon": "build/icon.icns"
    },
    "publish": {
      "provider": "generic",
      "url": "THE_RELEASE_URL_HERE",
      "channel": "latest",
      "publishAutoUpdate": true
    }
  },
Run Code Online (Sandbox Code Playgroud)

我配置构建脚本"pack": "electron-builder --dir -mwl",script。问题是,当我运行该命令时npm run pack,它会为所有平台打包应用程序,但对于 Windows,没有单个安装程序文件.exe或“.msi”。electron-builder为 Windows 构建一堆文件。

我在 macOS High Sierra v10.13.6 (17G8030) 上运行。我也尝试在 Windows 10 系统上构建,但结果是一样的。这里是否配置错误,或者为 Windows 生成单个安装程序文件需要更多步骤?

Kir*_*iya 6

我想出了如何从电子源构建独立的安装程序,而不是拥有一堆文件。实际上我们必须使用electron-builderwith -p\n这是我的package.json文件中的构建配置。

\n\n
"build": {\n    "appId": "com.trinityinfosystem.accurate",\n    "productName": "Accurate",\n    "copyright": "Copyright \xc2\xa9 2018 Trinity InfoSystem",\n    "mac": {\n      "target": [\n        "zip"\n      ],\n      "publish": [\n        "github"\n      ]\n    },\n    "win": {\n      "publisherName": "Trinity InfoSystem",\n      "publish": [\n        "github"\n      ],\n      "target": [\n        "nsis"\n      ]\n    },\n    "linux": {\n      "target": [\n        "AppImage",\n        "tar.gz"\n      ]\n    },\n    "dmg": {\n      "icon": "build/icon.icns"\n    },\n    "publish": [\n      {\n        "provider": "github",\n        "owner": "vkiranmaniya",\n        "repo": "accurate",\n        "vPrefixedTagName": true,\n        "private": true,\n        "releaseType": "draft"\n      }\n    ]\n  }\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我就使用了它electron-builder -p never --win,并将.exe文件打包到了project_root/dist目录中。-p always如果您正在使用auto-updatorfromelectron-builder并希望在 github 存储库中发布发布草稿,则可以使用。

\n\n

如果您想覆盖默认安装位置并让用户选择它,请确保您已nsis按如下方式配置构建,

\n\n
"nsis": {\n      "oneClick": false,\n      "perMachine": false,\n      "allowToChangeInstallationDirectory": true\n},\n
Run Code Online (Sandbox Code Playgroud)\n