Overview概述

How to configure Electron Forge如何配置Electron Forge

Electron Forge configuration is centralized in a single configuration object. Electron Forge配置集中在一个配置对象中。You can specify this config in your package.json on the config.forge property. 您可以在config.forge属性的package.json中指定此配置。This property can have be in one of two forms:此属性可以是以下两种形式之一:

If you do not have config.forge set in your package.json file, Forge will attempt to find a forge.config.js file in your project root.如果您的package.json文件中没有设置config.forgeForge将尝试在项目根目录中找到一个forge.config.js文件。

module.exports = {
  packagerConfig: {},
  makers: [
    {
      name: '@electron-forge/maker-zip'
    }
  ]
};
{
  "name": "my-app",
  "version": "0.0.1",
  "config": {
    "forge": {
      "packagerConfig": {},
      "makers": [
        {
          "name": "@electron-forge/maker-zip"
        }
      ]
    }
  }
}

We recommend using using JavaScript for your config file since it enables conditional logic within your configuration.我们建议在配置文件中使用JavaScript,因为它可以在配置中启用条件逻辑。

Configuration options配置选项

module.exports = {
  packagerConfig: { /* ... */ },
  rebuildConfig: { /* ... */ },
  makers: [],
  publishers: [],
  plugins: [],
  hooks: { /* ... */ },
  buildIdentifier: 'my-build'
};
// Only the relevant section of package.json is shown, for brevity.为了简洁起见,只显示了package.json的相关部分。
{
  "config": {
    "forge": {
      "packagerConfig": { ... },
      "rebuildConfig": { ... },
      "makers": [ ... ],
      "publishers": [ ... ],
      "plugins": [ ... ],
      "hooks": { ... },
      "buildIdentifier": "my-build"
    }
  }
}

All properties are optional所有属性都是可选的

Electron Packager config打包器配置

The top level property packagerConfig on the configuration object maps directly to the options sent to electron-packager during the package step of Electron Forge's build process.配置对象上的顶级属性packageConfig直接映射到在electron Forge构建过程的封装步骤中发送给electron-packager的选项。

The options you can put in this object are documented in the Electron Packager API docs.您可以放入该对象中的选项在Electron Packager API文档中有文档说明。

You can not override the dir, arch, platform, out or electronVersion options as they are set by Electron Forge internally.您不能覆盖dirarchplatformoutelectronVersion选项,因为它们是由Electron Forge内部设置的。

Electron Rebuild config重新生成配置

The top level property rebuildConfig on the configuration object maps directly to the options sent to electron-rebuild during both the package and start step of Electron Forge's build process.配置对象上的顶级属性rebuildConfig直接映射到在electron-rebuild的构建过程的封装和启动步骤期间发送给电子重建的选项。

The options you can put in this object are documented in the Electron Rebuild API docs.Electron Rebuild API文档中记录了可以放入此对象中的选项。

You can not override the buildPath, arch, or electronVersion options as they are set by Electron Forge internally您不能覆盖buildPatharchelectronVersion选项,因为它们是由Electron Forge内部设置的

Makers

The top level property makers on the configuration object is an array of maker configurations. 配置对象上的顶级属性makers是生成器配置的数组。Check out the Makers documentation for all possible makers and their config options.查看制造商文档,了解所有可能的制造商及其配置选项。

Publishers

The top level property publishers on the configuration object is an array of publisher configurations. 配置对象上的顶级属性publishers是一组发布者配置。Check out the Publishers documentation for all possible publishers and their config options.查看发布者文档,了解所有可能的发布者及其配置选项。

Plugins

The top level property plugins on the configuration object is an array of plugin configurations. 配置对象上的顶级属性plugins是一组插件配置。Check out the Plugins documentation for all possible plugins and their config options.查看插件文档,了解所有可能的插件及其配置选项。

Hooks

The top level property hooks on the configuration object is an object containing hooks that can be used to insert custom logic during the build lifecycle.配置对象上的顶级属性hooks是一个包含挂钩的对象,这些挂钩可用于在构建生命周期中插入自定义逻辑。

Check out the Hooks documentation for all possible hooks and their config options.查看挂勾文档,了解所有可能的挂钩及其配置选项。

Build identifiers生成标识符

This property can be used to identify different build configurations. 此属性可用于标识不同的生成配置。Normally, this property is set to the channel the build will release to, or some other unique identifier. 通常,此属性设置为生成将发布到的通道,或其他一些唯一标识符。For example, common values are prod and beta. 例如,常见的值是prodbetaThis identifier can be used in conjunction with the fromBuildIdentifier function to generate release channel or environment specific configuration. 此标识符可以与fromBuildIdentifier函数结合使用,以生成发布通道或特定于环境的配置。For example:例如:

const { utils: { fromBuildIdentifier } } = require('@electron-forge/core');
​
module.exports = {
  buildIdentifier: process.env.IS_BETA ? 'beta' : 'prod',
  packagerConfig: {
    appBundleId: fromBuildIdentifier({ beta: 'com.beta.app', prod: 'com.app' })
  }
};

In this example the appBundleId option passed to Electron Packager will be selected based on the buildIdentifer based on whether you are building for prod or beta. 在本例中,传递给Electron Packager的appBundleId选项将根据buildIdentifer进行选择,具体取决于您是为prod还是beta进行构建。This allows you to make shared configs incredibly easily as only the values that change need to be wrapped with this function.这允许您非常容易地进行共享配置,因为只有更改的值才需要使用此函数进行包装。