💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 如何阅读文档 * 可选属性(optional) 是正常的,必需的(required)是加粗的 * 在 属性名称(property name) 后边指定类型(type):`Array<String> | String` 这样的形式意味着你可以指定或者字符串(`**/*`)或字符串数组(`["**/*", "!foo.js"]`)。 [**configuration**](https://www.electron.build/configuration/configuration) electron-builder配置 可以这样定义: * 在 你项目文件的`package.json`顶层中,加上`build`键值(key),在最 ``` "bulid":{ "appID":"com.example.app" } ``` 或者通过--config <path/to/xxx.yml>、--config <path/to/xxx.json5>、--config <path/to/xxx.toml>、--config <path/to/xxx.js>选项,默认electron-builder.yml 如:electron-builder.yml配置如下 ``` appID:"com.example.app" ``` 格式如下图: ![](https://img.kancloud.cn/63/f4/63f49f9d23b2898676594ff27aba8795_344x126.png) 如果你想使用`toml`请使用`yarn add toml --dev`命令安装 . # **配置(Configuration)** * `appId`\=`com.electron.${name}`String - 应用程序id,用作`MacOs`的[CFBundleIdentifier](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070)和`Windows`的[Application User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx)(仅限NSIS目标,不支持Squirrel.Windows),强烈建议设置明确的ID。 * `productName`String - 打包后可执行文件的名称如(xxx.exe) * `copyright`=`Copyright © year ${author}`String - 该应用的版权信息. * * * * `directories` * `buildResources`=`build`String - 打包文件所需的资源的存放文件夹名默认build 请注意-Resources 并未打包进应用程序,如果你需要使用到某些文件,例如 托盘程序图标(tray icon),请明确指明需要包含的文件,请使用files:`"files": ["**/*", "build/icon.*"]` * `output`=`dist`String - 成功打包后的文件的存放文件夹名默认dist * `app`String - 应用程序目录(包含应用程序的 package.json)默认指向`app`,`www`,或者工作目录(working directory) * `mac`[MacConfiguration](https://www.electron.build/configuration/mac)\- Options related to how build macOS targets. * `mas`[MasConfiguration](https://www.electron.build/configuration/mas)\- MAS (Mac Application Store) options. * `dmg`[DmgOptions](https://www.electron.build/configuration/dmg)\- macOS DMG options. * `pkg`[PkgOptions](https://www.electron.build/configuration/pkg)\- macOS PKG options. * `win`[WindowsConfiguration](https://www.electron.build/configuration/win)\- Options related to how build Windows targets. * `nsis`[NsisOptions](https://www.electron.build/configuration/nsis) * `nsisWeb`- Web安装程序选项. 继承[NsisOptions](https://www.electron.build/configuration/nsis)选项. * `appPackageUrl`String - 应用程序包下载URL。可选的 —默认情况下使用 publish configuration. URL like`https://example.com/download/latest`allows web installer to be version independent (installer will download latest application package). Please note — it is[full URL](https://github.com/electron-userland/electron-builder/issues/1810#issuecomment-317650878). Custom`X-Arch`http header is set to`32`or`64`. * `artifactName`String - The[artifact file name template](https://www.electron.build/configuration/configuration#artifact-file-name-template). Defaults to`${productName} Web Setup ${version}.${ext}`. * `portable`\- Portable options. * `requestExecutionLevel`\=`user`“user” | “highest” | “admin” - The[requested execution level](http://nsis.sourceforge.net/Reference/RequestExecutionLevel)for Windows. * `unpackDirName`String - The unpack directory name in[TEMP](https://www.askvg.com/where-does-windows-store-temporary-files-and-how-to-change-temp-folder-location/)directory. Defaults to[uuid](https://github.com/segmentio/ksuid)of build (changed on each build of portable executable). * `appx`[AppXOptions](https://www.electron.build/configuration/appx) * `squirrelWindows`[SquirrelWindowsOptions](https://www.electron.build/configuration/squirrel-windows) * * * * `linux`[LinuxConfiguration](https://www.electron.build/configuration/linux)\- Options related to how build Linux targets. * `deb`[DebOptions](https://www.electron.build/configuration/linux#de)\- Debian package options. * `snap`[SnapOptions](https://www.electron.build/configuration/snap)\- Snap options. * `appImage`[AppImageOptions](https://www.electron.build/configuration/linux#appimageoptions)\- AppImage options. * `pacman`[LinuxTargetSpecificOptions](https://www.electron.build/configuration/linux#LinuxTargetSpecificOptions) * `rpm`[LinuxTargetSpecificOptions](https://www.electron.build/configuration/linux#LinuxTargetSpecificOptions) * `freebsd`[LinuxTargetSpecificOptions](https://www.electron.build/configuration/linux#LinuxTargetSpecificOptions) * `p5p`[LinuxTargetSpecificOptions](https://www.electron.build/configuration/linux#LinuxTargetSpecificOptions) * `apk`[LinuxTargetSpecificOptions](https://www.electron.build/configuration/linux#LinuxTargetSpecificOptions) * * * * `buildDependenciesFromSource`\=`false`Boolean - Whether to build the application native dependencies from source. * `nodeGypRebuild`\=`false`Boolean - Whether to execute`node-gyp rebuild`before starting to package the app. Don’t[use](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241214075)[npm](http://electron.atom.io/docs/tutorial/using-native-node-modules/#using-npm)(neither`.npmrc`) for configuring electron headers. Use`electron-builder node-gyp-rebuild`instead. * `npmArgs`Array | String - Additional command line arguments to use when installing app native deps. * `npmRebuild`\=`true`Boolean - Whether to[rebuild](https://docs.npmjs.com/cli/rebuild)native dependencies before starting to package the app. * * * * `buildVersion`String - The build version. Maps to the`CFBundleVersion`on macOS, and`FileVersion`metadata property on Windows. Defaults to the`version`. If`TRAVIS_BUILD_NUMBER`or`APPVEYOR_BUILD_NUMBER`or`CIRCLE_BUILD_NUM`or`BUILD_NUMBER`or`bamboo.buildNumber`or`CI_PIPELINE_IID`env defined, it will be used as a build version (`version.build_number`). * `electronCompile`Boolean - Whether to use[electron-compile](http://github.com/electron/electron-compile)to compile app. Defaults to`true`if`electron-compile`in the dependencies. And`false`if in the`devDependencies`or doesn’t specified. * `electronDist`String - The path to custom Electron build (e.g.`~/electron/out/R`). * `electronDownload`\- The[electron-download](https://github.com/electron-userland/electron-download#usage)options. * `version`String * `cache`String - The[cache location](https://github.com/electron-userland/electron-download#cache-location). * `mirror`String - The mirror. * `strictSSL`Boolean * `isVerifyChecksum`Boolean * `platform`“darwin” | “linux” | “win32” | “mas” * `arch`String * `electronVersion`String - The version of electron you are packaging for. Defaults to version of`electron`,`electron-prebuilt`or`electron-prebuilt-compile`dependency. * `extends`String - The name of a built-in configuration preset or path to config file (relative to project dir). Currently, only`react-cra`is supported. If`react-scripts`in the app dependencies,`react-cra`will be set automatically. Set to`null`to disable automatic detection. * `extraMetadata`any - Inject properties to`package.json`. * `readonly`\=`false`Boolean - Whether to fail if the application is not signed (to prevent unsigned app if code signing configuration is not correct). * `nodeVersion`String -*libui-based frameworks only*The version of NodeJS you are packaging for. You can set it to`current`to set the Node.js version that you use to run. * `launchUiVersion`Boolean | String -*libui-based frameworks only*The version of LaunchUI you are packaging for. Applicable for Windows only. Defaults to version suitable for used framework version. * `framework`String - The framework name. One of`electron`,`proton-native`,`libui`. Defaults to`electron`. * * * * `afterPack`\- The function (or path to file or module id) to be[run after pack](https://www.electron.build/configuration/configuration#afterpack)(but before pack into distributable format and sign). * `afterSign`\- The function (or path to file or module id) to be[run after pack and sign](https://www.electron.build/configuration/configuration#aftersign)(but before pack into distributable format). * `artifactBuildStarted`module:app-builder-lib/out/configuration.\_\_type | String - The function (or path to file or module id) to be run on artifact build start. * `artifactBuildCompleted`module:app-builder-lib/out/configuration.\_\_type | String - The function (or path to file or module id) to be run on artifact build completed. * `afterAllArtifactBuild`\- The function (or path to file or module id) to be[run after all artifacts are build](https://www.electron.build/configuration/configuration#afterAllArtifactBuild). * `onNodeModuleFile`\- The function (or path to file or module id) to be[run on each node module](https://www.electron.build/configuration/configuration#onnodemodulefile)file. * `beforeBuild`(context: BeforeBuildContext) => Promise | null - The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when`npmRebuild`is set to`true`. Resolving to`false`will skip dependencies install or rebuild. If provided and`node_modules`are missing, it will not invoke production dependencies check. * * * * `remoteBuild`\=`true`Boolean - Whether to build using Electron Build Service if target not supported on current OS. * `includePdb`\=`false`Boolean - Whether to include PDB files. * `removePackageScripts`\=`true`Boolean - Whether to remove`scripts`field from`package.json`files. * * * ### Overridable per Platform Options[¶](https://www.electron.build/configuration/configuration#overridable-per-platform-options "Permanent link") Following options can be set also per platform (top-level keys[mac](https://www.electron.build/configuration/mac),[linux](https://www.electron.build/configuration/linux)and[win](https://www.electron.build/configuration/win)) if need. * `appId`\=`com.electron.${name}`String - The application id. Used as[CFBundleIdentifier](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070)for MacOS and as[Application User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx)for Windows (NSIS target only, Squirrel.Windows not supported). It is strongly recommended that an explicit ID is set. * `artifactName`String - The[artifact file name template](https://www.electron.build/configuration/configuration#artifact-file-name-template). Defaults to`${productName}-${version}.${ext}`(some target can have other defaults, see corresponding options). * `compression`\=`normal`“store” | “normal” | “maximum” - The compression level. If you want to rapidly test build,`store`can reduce build time significantly.`maximum`doesn’t lead to noticeable size difference, but increase build time. * `files`The[files](https://www.electron.build/configuration/contents#files)configuration. * `extraResources`The[extra resources](https://www.electron.build/configuration/contents#extraresources)configuration. * `extraFiles`The[extra files](https://www.electron.build/configuration/contents#extrafiles)configuration. * `asar`\=`true`AsarOptions | Boolean\- Whether to package the application’s source code into an archive, using[Electron’s archive format](http://electron.atom.io/docs/tutorial/application-packaging/). Node modules, that must be unpacked, will be detected automatically, you don’t need to explicitly set[asarUnpack](https://www.electron.build/configuration/configuration#configuration-asarUnpack)\- please file an issue if this doesn’t work. * `smartUnpack`\=`true`Boolean - Whether to automatically unpack executables files. * `ordering`String * `asarUnpack`Array | String - A[glob patterns](https://www.electron.build/file-patterns)relative to the[app directory](https://www.electron.build/configuration/configuration#MetadataDirectories-app), which specifies which files to unpack when creating the[asar](http://electron.atom.io/docs/tutorial/application-packaging/)archive. * * * * `fileAssociations`Array | FileAssociation\- The file associations. * **`ext`**String | Array - The extension (minus the leading period). e.g.`png`. * `name`String - The name. e.g.`PNG`. Defaults to`ext`. * `description`String -*windows-only.*The description. * `mimeType`String -*linux-only.*The mime-type. * `icon`String - The path to icon (`.icns`for MacOS and`.ico`for Windows), relative to`build`(build resources directory). Defaults to`${firstExt}.icns`/`${firstExt}.ico`(if several extensions specified, first is used) or to application icon. Not supported on Linux, file issue if need (default icon will be`x-office-document`). * `role`\=`Editor`String -*macOS-only*The app’s role with respect to the type. The value can be`Editor`,`Viewer`,`Shell`, or`None`. Corresponds to`CFBundleTypeRole`. * `isPackage`Boolean -*macOS-only*Whether the document is distributed as a bundle. If set to true, the bundle directory is treated as a file. Corresponds to`LSTypeIsPackage`. * `protocols`Array | Protocol\- The URL protocol schemes. * **`name`**String - The name. e.g.`IRC server URL`. * **`schemes`**Array - The schemes. e.g.`["irc", "ircs"]`. * `role`\=`Editor`“Editor” | “Viewer” | “Shell” | “None” -*macOS-only*The app’s role with respect to the type. * * * * `forceCodeSigning`Boolean - Whether to fail if app will be not code signed. * `electronUpdaterCompatibility`String - The[electron-updater compatibility](https://www.electron.build/auto-update#compatibility)semver range. * `publish`The[publish](https://www.electron.build/configuration/publish)options. * `detectUpdateChannel`\=`true`Boolean - Whether to infer update channel from application version pre-release components. e.g. if version`0.12.1-alpha.1`, channel will be set to`alpha`. Otherwise to`latest`. * `generateUpdatesFilesForAllChannels`\=`false`Boolean - Please see[Building and Releasing using Channels](https://github.com/electron-userland/electron-builder/issues/1182#issuecomment-324947139). * `releaseInfo`\- The release info. Intended for command line usage: `-c.releaseInfo.releaseNotes="new features"` * `releaseName`String - The release name. * `releaseNotes`String - The release notes. * `releaseNotesFile`String - The path to release notes file. Defaults to`release-notes-${platform}.md`(where`platform`it is current platform —`mac`,`linux`or`windows`) or`release-notes.md`in the[build resources](https://www.electron.build/configuration/configuration#MetadataDirectories-buildResources). * `releaseDate`String - The release date. * `target`String |[TargetConfiguration](https://www.electron.build/cli#targetconfiguration) ## Metadata[¶](https://www.electron.build/configuration/configuration#metadata "Permanent link") Some standard fields should be defined in the`package.json`. * **`name`**String - The application name. * `description`String - The application description. * `homepage`String - The url to the project[homepage](https://docs.npmjs.com/files/package.json#homepage)(NuGet Package`projectUrl`(optional) or Linux Package URL (required)). If not specified and your project repository is public on GitHub, it will be`https://github.com/${user}/${project}`by default. * `license`String -*linux-only.*The[license](https://docs.npmjs.com/files/package.json#license)name. * `author` * **`name`**String * `email`String * `repository`String | RepositoryInfo\- The[repository](https://docs.npmjs.com/files/package.json#repository). * **`url`**String * `build`[Configuration](https://www.electron.build/configuration/configuration#configuration)\- The electron-builder configuration.