任何 Windows 目标
顶层 win 键包含一组选项,用于指示 electron-builder 应如何构建 Windows 目标。这些选项适用于任何 Windows 目标。
常见问题¶
如何委托代码签名?¶
使用 sign 选项。另请参阅 为什么 sign.js 被调用 8 次。
"win": {
"signtoolOptions": {
"sign": "./customSign.js"
}
}
项目根目录中的文件 customSign.js
exports.default = async function(configuration) {
// your custom code
}
如何使用自定义验证函数来启用 nsis 签名验证替代方案,而不是 powershell?¶
使用 verifyUpdateCodeSignature
接口
/**
* return null if verify signature succeed
* return error message if verify signature failed
*/
export type verifyUpdateCodeSignature = (publisherName: string[], path: string) => Promise<string | null>
将自定义验证函数传递给 nsis 更新程序。例如,如果您想使用原生验证函数,可以使用 win-verify-signature。
import { NsisUpdater } from "electron-updater"
import { verifySignatureByPublishName } from "win-verify-signature"
// Or MacUpdater, AppImageUpdater
export default class AppUpdater {
constructor() {
const options = {
requestHeaders: {
// Any request headers to include here
},
provider: 'generic',
url: 'https://example.com/auto-updates'
}
const autoUpdater = new NsisUpdater(options)
autoUpdater.verifyUpdateCodeSignature = (publisherName: string[], path: string) => {
const result = verifySignatureByPublishName(path, publisherName);
if(result.signed) return Promise.resolve(null);
return Promise.resolve(result.message);
}
autoUpdater.addAuthHeader(`Bearer ${token}`)
autoUpdater.checkForUpdatesAndNotify()
}
}
如何创建 Parallels Windows 10 虚拟机?¶
禁用 “与 Windows 共享 Mac 用户文件夹”
如果您使用 Parallels,则 绝不能使用 “与 Windows 共享 Mac 用户文件夹” 功能,并且不得从此类文件夹运行安装程序。
您不需要拥有 Windows 10 许可证。免费提供(90 天后过期,但这不是问题,因为不需要额外的设置)。
- 打开 Parallels Desktop。
- 文件 -> 新建。
- 在 “免费系统” 中选择 “Modern.IE”。
- 继续,继续,接受软件许可协议。
- 选择 “Microsoft Edge on Windows 10”。
- 接下来的步骤是通用的,请参阅 在 Mac 上使用 Parallels Desktop 安装 Windows,从 “步骤 6:指定名称和位置” 开始。
Parallels Windows 10 虚拟机将自动用于在 macOS 上构建 AppX。无需甚至启动虚拟机 — 它将在需要时自动启动,并在构建后暂停。无需指定虚拟机 — 它将被自动检测到(将使用第一个 Windows 10 虚拟机)。
如何创建 VirtualBox Windows 10 虚拟机?¶
如果您不在 macOS 上,或者不想购买 Parallels Desktop,您可以使用免费的 VirtualBox。
您的虚拟机的密码是 Passw0rd!
。
electron-builder 目前不支持 VirtualBox,因此,如果您想使用 VirtualBox 构建 AppX(和其他仅限 Windows 的任务),您需要在 Windows 上设置构建环境。
配置¶
Electron-Builder / app-builder-lib / WindowsConfiguration
扩展¶
属性¶
appId?¶
readonly
optional
appId:null
|string
应用程序 ID。用于 MacOS 的 CFBundleIdentifier 和 Windows 的 应用程序用户模型 ID(仅限 NSIS 目标,不支持 Squirrel.Windows)。强烈建议设置显式 ID。
默认¶
com.electron.${name}
继承自¶
PlatformSpecificBuildOptions
.appId
artifactName?¶
readonly
optional
artifactName:null
|string
工件文件名模板。默认为 ${productName}-${version}.${ext}
(某些目标可能具有其他默认值,请参阅相应的选项)。
继承自¶
PlatformSpecificBuildOptions
.artifactName
asar?¶
readonly
optional
asar:null
|boolean
|AsarOptions
是否使用 Electron 的归档格式 将应用程序的源代码打包到归档文件中。
必须解压缩的 Node 模块将自动检测,您无需显式设置 asarUnpack - 如果这不起作用,请提交问题。
默认¶
true
继承自¶
PlatformSpecificBuildOptions
.asar
asarUnpack?¶
readonly
optional
asarUnpack:null
|string
|string
[]
相对于 应用程序目录 的 glob 模式,用于指定在创建 asar 归档文件时要解压缩的文件。
继承自¶
PlatformSpecificBuildOptions
.asarUnpack
azureSignOptions?¶
readonly
optional
azureSignOptions:null
|WindowsAzureSigningConfiguration
使用 Azure Trusted Signing(beta 版)的选项。不能与 signtoolOptions
结合使用,签名将默认为 Azure Trusted Signing
compression?¶
readonly
optional
compression:null
|CompressionLevel
压缩级别。如果您想快速测试构建,store
可以显着减少构建时间。maximum
不会导致明显的尺寸差异,但会增加构建时间。
默认¶
normal
继承自¶
PlatformSpecificBuildOptions
.compression
cscKeyPassword?¶
optional
cscKeyPassword:null
|string
继承自¶
PlatformSpecificBuildOptions
.cscKeyPassword
cscLink?¶
optional
cscLink:null
|string
继承自¶
PlatformSpecificBuildOptions
.cscLink
defaultArch?¶
readonly
optional
defaultArch:string
继承自¶
PlatformSpecificBuildOptions
.defaultArch
detectUpdateChannel?¶
readonly
optional
detectUpdateChannel:boolean
是否从应用程序版本预发布组件推断更新渠道。例如,如果版本为 0.12.1-alpha.1
,渠道将设置为 alpha
。否则为 latest
。这不适用于 github 发布,github 发布永远不会自动检测更新渠道。
默认¶
true
继承自¶
PlatformSpecificBuildOptions
.detectUpdateChannel
disableDefaultIgnoredFiles?¶
optional
disableDefaultIgnoredFiles:null
|boolean
是否排除所有默认忽略的文件 (https://builder.electron.js.cn/contents#files) 和选项。默认为 false
。
默认¶
false
继承自¶
PlatformSpecificBuildOptions
.disableDefaultIgnoredFiles
electronLanguages?¶
readonly
optional
electronLanguages:string
|string
[]
要保留的 electron 语言环境。默认情况下,所有 Electron 语言环境都按原样使用。
继承自¶
PlatformSpecificBuildOptions
.electronLanguages
electronUpdaterCompatibility?¶
readonly
optional
electronUpdaterCompatibility:null
|string
electron-updater 兼容性 semver 范围。
继承自¶
PlatformSpecificBuildOptions
.electronUpdaterCompatibility
executableName?¶
readonly
optional
executableName:null
|string
可执行文件名。默认为 productName
。
继承自¶
PlatformSpecificBuildOptions
.executableName
extraFiles?¶
optional
extraFiles:null
|string
|FileSet
| (string
|FileSet
)[]
与 extraResources 相同,但复制到应用程序的内容目录中(MacOS 的 Contents
,Linux 和 Windows 的根目录)。
继承自¶
PlatformSpecificBuildOptions
.extraFiles
extraResources?¶
optional
extraResources:null
|string
|FileSet
| (string
|FileSet
)[]
相对于项目目录的 glob 模式,如果指定,则将具有匹配名称的文件或目录直接复制到应用程序的 resources 目录中(MacOS 的 Contents/Resources
,Linux 和 Windows 的 resources
)。
文件模式(以及对 from
和 to
字段的支持)与 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"]
}
]
您也可以在 from
和 to
字段中使用 文件宏。from
和 to
可以是文件,您可以使用它在打包时重命名文件。
继承自¶
PlatformSpecificBuildOptions
.files
forceCodeSigning?¶
readonly
optional
forceCodeSigning:boolean
如果应用程序未进行代码签名,是否失败。
继承自¶
PlatformSpecificBuildOptions
.forceCodeSigning
generateUpdatesFilesForAllChannels?¶
readonly
optional
generateUpdatesFilesForAllChannels:boolean
请参阅 使用渠道构建和发布。
默认¶
false
继承自¶
PlatformSpecificBuildOptions
.generateUpdatesFilesForAllChannels
icon?¶
readonly
optional
icon:null
|string
应用程序图标的路径。
默认¶
build/icon.ico
覆盖¶
PlatformSpecificBuildOptions
.icon
legalTrademarks?¶
readonly
optional
legalTrademarks:null
|string
商标和注册商标。
protocols?¶
URL 协议方案。
继承自¶
PlatformSpecificBuildOptions
.protocols
publish?¶
optional
publish:Publish
发布者配置。有关更多信息,请参阅 自动更新。
继承自¶
PlatformSpecificBuildOptions
.publish
releaseInfo?¶
readonly
optional
releaseInfo:ReleaseInfo
发布信息。旨在用于命令行
-c.releaseInfo.releaseNotes="new features"
继承自¶
PlatformSpecificBuildOptions
.releaseInfo
requestedExecutionLevel?¶
readonly
optional
requestedExecutionLevel:null
|RequestedExecutionLevel
应用程序请求执行的安全级别。不能按目标指定,仅允许在 win
中指定。
默认¶
asInvoker
signAndEditExecutable?¶
readonly
optional
signAndEditExecutable:boolean
是否签名并将元数据添加到可执行文件。高级选项。
默认¶
true
signExts?¶
readonly
optional
signExts:null
|string
[]
也要签名的显式文件扩展名。高级选项。
参见¶
https://github.com/electron-userland/electron-builder/issues/7329
默认¶
null
signtoolOptions?¶
readonly
optional
signtoolOptions:null
|WindowsSigntoolConfiguration
与 signtool.exe 一起使用的选项。不能与 azureSignOptions
结合使用,签名将默认为 Azure Trusted Signing
target?¶
readonly
optional
target:TargetConfigType
目标包类型:nsis
、nsis-web
(Web 安装程序)、portable
(没有安装的 [portable]./nsis.md#portable 应用程序)、appx
、msi
、msi-wrapped
、squirrel
、7z
、zip
、tar.xz
、tar.lz
、tar.gz
、tar.bz2
、dir
列表。AppX 包只能在 Windows 10 上构建。
要使用 Squirrel.Windows,请安装 electron-builder-squirrel-windows
依赖项。
默认¶
nsis
覆盖¶
PlatformSpecificBuildOptions
.target
verifyUpdateCodeSignature?¶
readonly
optional
verifyUpdateCodeSignature:boolean
是否在安装前验证可用更新的签名。发布者名称将用于签名验证。
默认¶
true