electron-builder 打包[推荐]

最后更新于:2022-04-02 03:34:54

[TOC] > [electron-builder打包见解 ](https://juejin.im/post/5bc53aade51d453df0447927) > [electron-builder 官网](https://www.electron.build/file-patterns#file-macros) ## 特点 * electron-builder 可以打包成msi、exe、dmg文件,macOS系统,只能打包dmg文件,window系统才能打包exe,msi文件; * 几乎支持了所有平台的所有格式; * 可以将prepackage目录(手动或使用electron-packager生成的目录)打包成安装包; * 支持[Auto Update](https://link.jianshu.com?t=https://github.com/electron-userland/electron-builder/wiki/Auto-Update); * [非常丰富的选项](https://link.jianshu.com?t=https://github.com/electron-userland/electron-builder/wiki/Options); * 支持CLI和JS API两种使用方式; ## 完整配置 基本上可用的完整的配置 ``` "build": { "productName": "ele_demo", "artifactName": "${productName}-${version}.${ext}", "appId": "com.electron.idcpj", "copyright": "Copyright © year ${author}", "directories": { "output": "dist" }, "publish": [ { "provider": "generic", "url": "https://github.com/idcpj/electron_demo/demo" } ], "dmg": { "contents": [ { "x": 410, "y": 150, "type": "link", "path": "/Applications" }, { "x": 130, "y": 150, "type": "file" } ] }, "mac": { "category": "public.app-category.developer-tools" }, "win": { "icon": "assets/img/ele.png", "target": [ "nsis" ] }, "nsis": { "oneClick": false, "allowElevation": true, "allowToChangeInstallationDirectory": true, "createDesktopShortcut": true, "createStartMenuShortcut": true, "shortcutName": "ele_图标名", "include": "script/builder.nsi" //默认省略,需要定制时,使用自定义的nsi } }, ``` ## 命令行参数(CLI) ``` electron-builder build 构建命名 [default] electron-builder install-app-deps 下载app依赖 electron-builder node-gyp-rebuild 重建自己的本机代码 electron-builder create-self-signed-cert 为Windows应用程序创建自签名代码签名证书 electron-builder start 使用electronic-webpack在开发模式下运行应用程序(须臾要electron-webpack模块支持) ``` ### Building(构建参数): ``` --mac, -m, -o, --macos Build for macOS, [array] --linux, -l Build for Linux [array] --win, -w, --windows Build for Windows [array] --x64 Build for x64 (64位安装包) [boolean] --ia32 Build for ia32(32位安装包) [boolean] --armv7l Build for armv7l [boolean] --arm64 Build for arm64 [boolean] --dir Build unpacked dir. Useful to test. [boolean] --prepackaged, --pd 预打包应用程序的路径(以可分发的格式打包) --projectDir, --project 项目目录的路径。 默认为当前工作目录。 --config, -c 配置文件路径。 默认为`electron-builder.yml`(或`js`,或`js5`) ``` Publishing(发布): ` --publish, -p 发布到GitHub Releases [choices: "onTag", "onTagOrDraft", "always", "never", undefined] `
';