跳到内容

命令行界面 (CLI)

Commands:
  electron-builder build                    Build                      [default]
  electron-builder install-app-deps         Install app deps
  electron-builder node-gyp-rebuild         Rebuild own native code
  electron-builder create-self-signed-cert  Create self-signed code signing cert
                                            for Windows apps
  electron-builder start                    Run application in a development
                                            mode using electron-webpack
  electron-builder publish                  Publish any files with your publish config

Building:
  --mac, -m, -o, --macos   Build for macOS, accepts target list (see
                           https://goo.gl/5uHuzj).                       [array]
  --linux, -l              Build for Linux, accepts target list (see
                           https://goo.gl/4vwQad)                        [array]
  --win, -w, --windows     Build for Windows, accepts target list (see
                           https://goo.gl/jYsTEJ)                        [array]
  --x64                    Build for x64                               [boolean]
  --ia32                   Build for ia32                              [boolean]
  --armv7l                 Build for armv7l                            [boolean]
  --arm64                  Build for arm64                             [boolean]
  --universal              Build for universal (mac only)              [boolean]
  --dir                    Build unpacked dir. Useful to test.         [boolean]
  --prepackaged, --pd      The path to prepackaged app (to pack in a
                           distributable format)
  --projectDir, --project  The path to project directory. Defaults to current
                           working directory.
  --config, -c             The path to an electron-builder config. Defaults to
                           `electron-builder.yml` (or `json`, or `json5`, or `js`, or `ts`), see
                           https://goo.gl/YFRJOM

Publishing:
  --publish, -p  Publish artifacts (to GitHub Releases), see
                 https://goo.gl/tSFycD
                [choices: "onTag", "onTagOrDraft", "always", "never", undefined]


-----

electron-builder publish

Publish a list of artifacts

Options:
  -v, --version  The app/build version used when searching for an upload release
                 (used by some Publishers)                              [string]
      --help     Show help                                             [boolean]
  -f, --files    The file(s) to upload to your publisher      [array] [required]
  -c, --config   The path to an electron-builder config. Defaults to
                 `electron-builder.yml` (or `json`, or `json5`, or `js`, or
                 `ts`), see https://goo.gl/YFRJOM                       [string]

Other:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

有关其他命令,请使用 --help 参数查看帮助,例如 ./node_modules/.bin/electron-builder install-app-deps --help

提示

由于 Node.js 8 npx 已捆绑,因此,您可以直接使用 npx electron-builder

如果您从终端而不是 package.json 脚本运行它,请在下面的示例命令前加上 npx

为 macOS、Windows 和 Linux 构建

electron-builder -mwl

为 Linux 构建 deb 和 tar.xz

electron-builder --linux deb tar.xz

为 Windows 构建 NSIS 32 位安装程序

electron-builder --windows nsis:ia32

将 package.json 属性 foo 设置为 bar

electron-builder -c.extraMetadata.foo=bar

为 NSIS 配置 unicode 选项

electron-builder -c.nsis.unicode=false

目标

如果没有目标配置,electron-builder 会使用默认目标为当前平台和当前架构构建 Electron 应用程序。

  • macOS - DMG 和 ZIP 用于 Squirrel.Mac。
  • Windows - [NSIS]./nsis.md)。
  • Linux
    • 如果您在 Windows 或 macOS 上构建:SnapAppImage 用于 x64。
    • 如果您在 Linux 上构建:SnapAppImage 用于当前架构。

平台和架构可以配置或使用 CLI 参数,或在配置中。

例如,如果您不想每次都传递 --ia32--x64 标志,而是默认构建适用于 Windows 所有架构的 NSIS 目标

配置

package.json

"build": {
  "win": {
    "target": [
      {
        "target": "nsis",
        "arch": [
          "x64",
          "ia32"
        ]
      }
    ]
  },
  "mac": {
    "target": [
      {
        "target": "dmg",
        "arch": [
          "universal"
        ]
      }
    ]
  }
}

electron-builder.yml

 win:
   target:
     - target: nsis
       arch:
         - x64
         - ia32
mac:
  target:
    - target: dmg
      arch: universal

electron-builder.config.js

module.exports = {
  "win": {
    "target": [
      {
        "target": "nsis",
        "arch": [
          "x64",
          "ia32"
        ]
      }
    ]
  },
  "mac": {
    "target": [
      {
        "target": "dmg",
        "arch": [
          "universal"
        ]
      }
    ]
  }
}

并使用

build -wl

目标配置

  • target 字符串 - 目标名称。例如,snap
  • arch “x64” | “ia32” | “armv7l” | “arm64” | “universal” - 架构或架构列表。