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:此属性可以是以下两种形式之一:
An object containing your entire Forge configuration.包含整个Forge配置的对象。A relative path pointing at a JavaScript file that exports your config.指向导出配置的JavaScript文件的相对路径。
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.forge
Forge将尝试在项目根目录中找到一个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.dir
、arch
、platform
、out
或electronVersion
选项,因为它们是由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 internallybuildPath
、arch
或electronVersion
选项,因为它们是由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
. prod
和beta
。This 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 在本例中,传递给Electron Packager的appBundleId
option passed to Electron Packager will be selected based on the buildIdentifer
based on whether you are building for prod
or beta
. 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.这允许您非常容易地进行共享配置,因为只有更改的值才需要使用此函数进行包装。