【问题标题】:Build standalone .exe from electron app using electron-builder使用 electron-builder 从电子应用程序构建独立的 .exe
【发布时间】:2020-01-22 09:36:13
【问题描述】:

我正在使用 electron v6.0.9 和 electron-builder 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
    }
  },

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

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

【问题讨论】:

  • 您在哪里定义了您用于 window 的方法?表示其nsis,appXsquirrel.windows
  • 看看我上面的package.json。我的目标是 nsis 和 zip
  • 我找到了"nsis": { "oneClick": false },但是,虽然这会创建安装弹出窗口,但它不会让用户选择哪个窗口? -- 没关系,它就在下面 :D 对垃圾邮件感到抱歉
  • 尝试在nsis 构建配置中添加"allowToChangeInstallationDirectory": true
  • 因为"allowToChangeInstallationDirectory" 默认为false。我认为我必须做到这一点

标签: windows macos electron installation electron-builder


【解决方案1】:

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

"build": {
    "appId": "com.trinityinfosystem.accurate",
    "productName": "Accurate",
    "copyright": "Copyright © 2018 Trinity InfoSystem",
    "mac": {
      "target": [
        "zip"
      ],
      "publish": [
        "github"
      ]
    },
    "win": {
      "publisherName": "Trinity InfoSystem",
      "publish": [
        "github"
      ],
      "target": [
        "nsis"
      ]
    },
    "linux": {
      "target": [
        "AppImage",
        "tar.gz"
      ]
    },
    "dmg": {
      "icon": "build/icon.icns"
    },
    "publish": [
      {
        "provider": "github",
        "owner": "vkiranmaniya",
        "repo": "accurate",
        "vPrefixedTagName": true,
        "private": true,
        "releaseType": "draft"
      }
    ]
  }

然后我只是使用了electron-builder -p never --win,它在 project_root/dist 目录中打包了 .exe 文件。如果您使用来自electron-builderauto-updator 并希望在github 存储库中发布发布草案,则可以使用-p always

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

"nsis": {
      "oneClick": false,
      "perMachine": false,
      "allowToChangeInstallationDirectory": true
},

【讨论】:

    猜你喜欢
    • 2017-03-04
    • 2019-10-05
    • 2021-10-14
    • 2021-09-21
    • 2010-09-06
    • 2021-02-17
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多