跳到内容

electron builder.Interface.Configuration

Electron-Builder / electron-builder / 配置

配置选项

继承

属性

afterAllArtifactBuild?

readonly optional afterAllArtifactBuild: null | string | Hook<BuildResult, string[]>

在所有构件构建完成后运行的函数(或文件路径或模块 ID)。

(buildResult: BuildResult): Promise<Array<string>> | Array<string>

配置方式与 afterPack 相同(见上文)。

myAfterAllArtifactBuild.js

exports.default = function () {
  // you can return additional files to publish
  return ["/path/to/additional/result/file"]
}

继承自

Hooks.afterAllArtifactBuild


afterExtract?

readonly optional afterExtract: null | string | Hook<PackContext, void>

预构建的 Electron 二进制文件提取到输出目录后 运行的函数(或文件路径或模块 ID)。设置方式与 beforePack 相同

继承自

Hooks.afterExtract


afterPack?

readonly optional afterPack: null | string | Hook<PackContext, void>

打包后(但在打包成可分发格式和签名之前)运行的函数(或文件路径或模块 ID)。设置方式与 beforePack 相同

继承自

Hooks.afterPack


afterSign?

readonly optional afterSign: null | string | Hook<PackContext, void>

打包和签名后(但在打包成可分发格式之前)运行的函数(或文件路径或模块 ID)。设置方式与 beforePack 相同

继承自

Hooks.afterSign


apk?

readonly optional apk: null | LinuxTargetSpecificOptions

继承自

CommonConfiguration.apk


appId?

readonly optional appId: null | string

应用程序 ID。用作 MacOS 的 CFBundleIdentifier 和 Windows 的 应用程序用户模型 ID(仅 NSIS 目标,不支持 Squirrel.Windows)。强烈建议设置显式 ID。

默认

com.electron.${name}

继承自

PlatformSpecificBuildOptions.appId


appImage?

readonly optional appImage: null | AppImageOptions

AppImage 选项。

继承自

CommonConfiguration.appImage


appx?

readonly optional appx: null | AppXOptions

继承自

CommonConfiguration.appx


appxManifestCreated?

readonly optional appxManifestCreated: null | string | Hook<string, void>

在磁盘上创建 Appx 清单后运行的函数(或文件路径或模块 ID) - 尚未打包到 .appx 包中。

继承自

Hooks.appxManifestCreated


artifactBuildCompleted?

readonly optional artifactBuildCompleted: null | string | Hook<ArtifactCreated, void>

在构件构建完成后运行的函数(或文件路径或模块 ID)。设置方式与 beforePack 相同

继承自

Hooks.artifactBuildCompleted


artifactBuildStarted?

readonly optional artifactBuildStarted: null | string | Hook<ArtifactBuildStarted, void>

在构件构建开始时运行的函数(或文件路径或模块 ID)。设置方式与 beforePack 相同

继承自

Hooks.artifactBuildStarted


artifactName?

readonly optional artifactName: null | string

构件文件名模板。默认为 ${productName}-${version}.${ext}(某些目标可能具有其他默认值,请参阅相应的选项)。

继承自

PlatformSpecificBuildOptions.artifactName


asar?

readonly optional asar: null | boolean | AsarOptions

是否使用 Electron 的归档格式 将应用程序的源代码打包到归档文件中。

必须解包的 Node 模块将自动检测,您无需显式设置 asarUnpack - 如果这不起作用,请提交 issue。

默认

true

继承自

PlatformSpecificBuildOptions.asar


asarUnpack?

readonly optional asarUnpack: null | string | string[]

相对于 应用程序目录glob 模式,指定在创建 asar 归档文件时要解包的文件。

继承自

PlatformSpecificBuildOptions.asarUnpack


beforeBuild?

readonly optional beforeBuild: null | string | Hook<BeforeBuildContext, boolean | void>

在安装或重建依赖项之前运行的函数(或文件路径或模块 ID)。当 npmRebuild 设置为 true 时有效。解析为 false 将跳过依赖项安装或重建。

如果提供且 node_modules 缺失,则不会调用生产依赖项检查。

继承自

Hooks.beforeBuild


beforePack?

readonly optional beforePack: null | string | Hook<PackContext, void>

在打包前运行的函数(或文件路径或模块 ID)。

(context: BeforePackContext): Promise<any> | any

作为函数

beforePack: async (context) => {
  // your code
}

由于在配置文件中不能使用 JavaScript,因此可以指定为文件路径或模块 ID。函数必须作为默认导出导出。

"build": {
  "beforePack": "./myBeforePackHook.js"
}

项目根目录中的文件 myBeforePackHook.js

myBeforePackHook.js

exports.default = async function(context) {
  // your custom code
}

继承自

Hooks.beforePack


buildDependenciesFromSource?

optional buildDependenciesFromSource: boolean

是否从源代码构建应用程序原生依赖项。

默认

false

继承自

CommonConfiguration.buildDependenciesFromSource


buildNumber?

readonly optional buildNumber: null | string

构建编号。映射到 Linux 上使用 FPM 构建的 --iteration 标志。如果未定义,则将回退到 BUILD_NUMBERTRAVIS_BUILD_NUMBERAPPVEYOR_BUILD_NUMBERCIRCLE_BUILD_NUMBUILD_BUILDNUMBERCI_PIPELINE_IID 环境变量。

继承自

CommonConfiguration.buildNumber


buildVersion?

readonly optional buildVersion: null | string

构建版本。映射到 macOS 上的 CFBundleVersion 和 Windows 上的 FileVersion 元数据属性。默认为 version。如果未定义 buildVersion 且定义了 buildNumber(或其中一个 buildNumber 环境变量),它将用作构建版本 (version.buildNumber)。

继承自

CommonConfiguration.buildVersion


compression?

readonly optional compression: null | CompressionLevel

压缩级别。如果您想快速测试构建,store 可以显着减少构建时间。maximum 不会导致明显的尺寸差异,但会增加构建时间。

默认

normal

继承自

PlatformSpecificBuildOptions.compression


readonly optional copyright: null | string

应用程序的人类可读版权行。

默认

Copyright © year ${author}

继承自

CommonConfiguration.copyright


cscKeyPassword?

optional cscKeyPassword: null | string

继承自

PlatformSpecificBuildOptions.cscKeyPassword


optional cscLink: null | string

继承自

PlatformSpecificBuildOptions.cscLink


deb?

readonly optional deb: null | DebOptions

Debian 包选项。

继承自

CommonConfiguration.deb


defaultArch?

readonly optional defaultArch: string

继承自

PlatformSpecificBuildOptions.defaultArch


detectUpdateChannel?

readonly optional detectUpdateChannel: boolean

是否从应用程序版本预发布组件推断更新频道。例如,如果版本为 0.12.1-alpha.1,频道将设置为 alpha。否则设置为 latest。这适用于 github 发布,它将 永远不会自动检测更新频道

默认

true

继承自

PlatformSpecificBuildOptions.detectUpdateChannel


directories?

readonly optional directories: null | MetadataDirectories

构建资源目录

继承自

CommonConfiguration.directories


disableDefaultIgnoredFiles?

optional disableDefaultIgnoredFiles: null | boolean

是否排除所有默认忽略的文件(https://builder.electron.js.cn/contents#files)和选项。默认为 false

默认

false

继承自

PlatformSpecificBuildOptions.disableDefaultIgnoredFiles


disableSanityCheckAsar?

readonly optional disableSanityCheckAsar: boolean

是否禁用完整性检查 asar 包(对于实现自己的加密完整性验证的自定义 electron 分支很有用)

默认

false

dmg?

readonly optional dmg: null | DmgOptions

macOS DMG 选项。

继承自

CommonConfiguration.dmg


downloadAlternateFFmpeg?

readonly optional downloadAlternateFFmpeg: boolean

是否从 Electron 的发布资产下载备用 FFmpeg 库,并在签名之前替换默认的 FFmpeg 库

继承自

CommonConfiguration.downloadAlternateFFmpeg


electronBranding?

readonly optional electronBranding: ElectronBrandingOptions

Electron 的可分发版本使用的品牌。如果 fork 修改了 Electron 的 BRANDING.json 文件,则需要此项。


electronCompile?

readonly optional electronCompile: boolean

是否使用 electron-compile 编译应用程序。如果依赖项中存在 electron-compile,则默认为 true。如果位于 devDependencies 中或未指定,则默认为 false


electronDist?

readonly optional electronDist: null | string | Hook<PrepareApplicationStageDirectoryOptions, string>

在暂存 electron 构件环境时运行的函数(或文件路径或模块 ID)。返回自定义 Electron 构建(例如 ~/electron/out/R)或 electron zip 文件目录的路径。

Zip 文件必须遵循模式 electron-v${version}-${platformName}-${arch}.zip,否则将被假定为解压后的 Electron 应用程序目录

继承自

Hooks.electronDist


electronDownload?

readonly optional electronDownload: ElectronDownloadOptions

electron-download 选项。


electronFuses?

readonly optional electronFuses: null | FuseOptionsV1

传递给 @electron/fuses 的选项。参考:https://github.com/electron/fuses

继承自

CommonConfiguration.electronFuses


electronLanguages?

readonly optional electronLanguages: string | string[]

要保留的 electron 语言环境。默认情况下,所有 Electron 语言环境都按原样使用。

继承自

PlatformSpecificBuildOptions.electronLanguages


electronUpdaterCompatibility?

readonly optional electronUpdaterCompatibility: null | string

electron-updater 兼容性 semver 范围。

继承自

PlatformSpecificBuildOptions.electronUpdaterCompatibility


electronVersion?

optional electronVersion: null | string

您要为其打包的 electron 版本。默认为 electronelectron-prebuiltelectron-prebuilt-compile 依赖项的版本。


executableName?

readonly optional executableName: null | string

可执行文件名。默认为 productName

继承自

PlatformSpecificBuildOptions.executableName


extends?

optional extends: null | string | string[]

内置配置预设的名称(目前仅支持 react-cra)或任意数量的配置文件路径(相对于项目目录)。

后者允许混合来自多个其他配置的配置,就像您 Object.assign 它们一样,但正确地组合 files glob 模式。

如果应用程序依赖项中存在 react-scripts,则会自动设置 react-cra。设置为 null 以禁用自动检测。


extraFiles?

optional extraFiles: null | string | FileSet | (string | FileSet)[]

extraResources 相同,但复制到应用程序的内容目录中(MacOS 为 Contents,Linux 和 Windows 为根目录)。

继承自

PlatformSpecificBuildOptions.extraFiles


extraMetadata?

readonly optional extraMetadata: any

将属性注入到 package.json 中。

继承自

CommonConfiguration.extraMetadata


extraResources?

optional extraResources: null | string | FileSet | (string | FileSet)[]

相对于项目目录的 glob 模式,指定后,将具有匹配名称的文件或目录直接复制到应用程序的 resources 目录中(MacOS 为 Contents/Resources,Linux 和 Windows 为 resources)。

文件模式(以及对 fromto 字段的支持)与 files 相同。

继承自

PlatformSpecificBuildOptions.extraResources


fileAssociations?

readonly optional fileAssociations: FileAssociation | FileAssociation[]

文件关联。

继承自

PlatformSpecificBuildOptions.fileAssociations


files?

optional files: null | string | FileSet | (string | FileSet)[]

相对于 应用程序目录glob 模式,指定在复制文件以创建包时要包含的文件。

默认为

[
"**/*",
"!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}",
"!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
"!**/node_modules/*.d.ts",
"!**/node_modules/.bin",
"!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}",
"!.editorconfig",
"!**/._*",
"!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,.gitignore,.gitattributes}",
"!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}",
"!**/{appveyor.yml,.travis.yml,circle.yml}",
"!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}"
]

在任何情况下都不会复制开发依赖项。您无需显式忽略它。默认情况下不忽略隐藏文件,但默认情况下会忽略所有应忽略的文件。

如果您的某些模式不是忽略模式(即不是以 ! 开头),则默认模式 **/* 不会添加到您的自定义模式中。在任何情况下,package.json**/node_modules/**/*(仅复制生产依赖项)都会添加到您的自定义模式中。所有默认忽略项都会在任何情况下添加 - 如果您配置自己的模式,则无需重复它。

可以在平台选项中指定(例如在 mac 中)。

您还可以通过使用 FileSet 对象而不是简单的 glob 模式来指定自定义源目录和目标目录。

[
{
 "from": "path/to/source",
 "to": "path/to/destination",
 "filter": ["**/*", "!foo/*.js"]
}
]

您可以在 fromto 字段中使用 文件宏fromto 可以是文件,您可以使用它在打包时重命名文件。

继承自

PlatformSpecificBuildOptions.files


flatpak?

readonly optional flatpak: null | FlatpakOptions

Flatpak 选项。

继承自

CommonConfiguration.flatpak


forceCodeSigning?

readonly optional forceCodeSigning: boolean

如果应用程序未签名是否失败(以防止在代码签名配置不正确时出现未签名的应用程序)。

默认

false

继承自

PlatformSpecificBuildOptions.forceCodeSigning


framework?

readonly optional framework: null | string

框架名称。electronprotonlibui 之一。默认为 electron


freebsd?

readonly optional freebsd: null | LinuxTargetSpecificOptions

继承自

CommonConfiguration.freebsd


generateUpdatesFilesForAllChannels?

readonly optional generateUpdatesFilesForAllChannels: boolean

请参阅 使用频道构建和发布

默认

false

继承自

PlatformSpecificBuildOptions.generateUpdatesFilesForAllChannels


icon?

readonly optional icon: null | string

继承自

PlatformSpecificBuildOptions.icon


includePdb?

readonly optional includePdb: boolean

是否包含 PDB 文件。

默认值

false

继承自

CommonConfiguration.includePdb


launchUiVersion?

readonly optional launchUiVersion: null | string | boolean

仅限基于 libui 的框架 您要打包的 LaunchUI 版本。仅适用于 Windows。默认为适用于所用框架版本的版本。


linux?

readonly optional linux: null | LinuxConfiguration

与如何构建 Linux 目标相关的选项。

继承自

CommonConfiguration.linux


mac?

readonly optional mac: null | MacConfiguration

与如何构建 macOS 目标相关的选项。

继承自

CommonConfiguration.mac


mas?

readonly optional mas: null | MasConfiguration

MAS (Mac Application Store) 选项。

继承自

CommonConfiguration.mas


masDev?

readonly optional masDev: null | MasConfiguration

MAS (Mac Application Store) 开发选项 (mas-dev 目标)。

继承自

CommonConfiguration.masDev


msiProjectCreated?

readonly optional msiProjectCreated: null | string | Hook<string, void>

在磁盘上创建 MSI 项目后(尚未打包到 .msi 包中)要运行的函数(或文件路径或模块 ID)。

继承自

Hooks.msiProjectCreated


nativeRebuilder?

readonly optional nativeRebuilder: null | "legacy" | "sequential" | "parallel"

使用 legacy app-builder 二进制文件安装原生依赖项,或在 sequentialparallel 编译模式下使用 @electron/rebuild

默认值

sequential

继承自

CommonConfiguration.nativeRebuilder


nodeGypRebuild?

readonly optional nodeGypRebuild: boolean

是否在开始打包应用程序之前执行 node-gyp rebuild

不要使用 npm(也不要使用 .npmrc)来配置 electron 标头。请改用 electron-builder node-gyp-rebuild

默认值

false

继承自

CommonConfiguration.nodeGypRebuild


nodeVersion?

readonly optional nodeVersion: null | string

仅限基于 libui 的框架 您要打包的 NodeJS 版本。您可以将其设置为 current 以设置您用来运行的 Node.js 版本。


npmArgs?

readonly optional npmArgs: null | string | string[]

安装应用程序原生依赖项时要使用的其他命令行参数。

继承自

CommonConfiguration.npmArgs


npmRebuild?

readonly optional npmRebuild: boolean

是否在开始打包应用程序之前重建原生依赖项。

默认值

true

继承自

CommonConfiguration.npmRebuild


nsis?

readonly optional nsis: null | NsisOptions

继承自

CommonConfiguration.nsis


nsisWeb?

readonly optional nsisWeb: null | NsisWebOptions

继承自

CommonConfiguration.nsisWeb


onNodeModuleFile?

readonly optional onNodeModuleFile: null | string | Hook<string, boolean | void>

在每个 node_module 文件上运行的函数(或文件路径或模块 ID)。返回 true/false 将确定是否强制包含或使用默认的复制器逻辑

继承自

Hooks.onNodeModuleFile


p5p?

readonly optional p5p: null | LinuxTargetSpecificOptions

继承自

CommonConfiguration.p5p


pacman?

readonly optional pacman: null | LinuxTargetSpecificOptions

继承自

CommonConfiguration.pacman


pkg?

readonly optional pkg: null | PkgOptions

macOS PKG 选项。

继承自

CommonConfiguration.pkg


portable?

readonly optional portable: null | PortableOptions

继承自

CommonConfiguration.portable


productName?

readonly optional productName: null | string

name相同,但允许您为可执行文件指定一个产品名称,其中包含空格和 name 属性中不允许的其他特殊字符。如果未在 build 配置中指定,则使用 package.json 顶层定义的 productName 属性。如果未在 package.json 顶层指定,则使用 name 属性

继承自

CommonConfiguration.productName


protocols?

readonly optional protocols: Protocol | Protocol[]

URL 协议方案。

继承自

PlatformSpecificBuildOptions.protocols


publish?

optional publish: Publish

发布者配置。有关更多信息,请参见自动更新

继承自

PlatformSpecificBuildOptions.publish


releaseInfo?

readonly optional releaseInfo: ReleaseInfo

发布信息。旨在用于命令行

-c.releaseInfo.releaseNotes="new features"

继承自

PlatformSpecificBuildOptions.releaseInfo


removePackageKeywords?

readonly optional removePackageKeywords: boolean

是否从 package.json 文件中删除 keywords 字段。

默认值

true

继承自

CommonConfiguration.removePackageKeywords


removePackageScripts?

readonly optional removePackageScripts: boolean

是否从 package.json 文件中删除 scripts 字段。

默认值

true

继承自

CommonConfiguration.removePackageScripts


rpm?

readonly optional rpm: null | LinuxTargetSpecificOptions

继承自

CommonConfiguration.rpm


snap?

readonly optional snap: null | SnapOptions

Snap 选项。

继承自

CommonConfiguration.snap


squirrelWindows?

readonly optional squirrelWindows: null | SquirrelWindowsOptions

继承自

CommonConfiguration.squirrelWindows


target?

readonly optional target: null | string | TargetConfiguration | (string | TargetConfiguration)[]

继承自

PlatformSpecificBuildOptions.target


win?

readonly optional win: null | WindowsConfiguration

与如何构建 Windows 目标相关的选项。

继承自

CommonConfiguration.win