electron打包以及应用自动更新
一.electron-builder
1.electron-builder安装及配置
安装命令:yarn add electron-builder --dev
或 npm install electron-builder --dev
(PS: 官方推荐使用yarn安装,说是能更好的处理依赖之间的关系)
安装好之后,配置package.json
文件:
"build": {
"appId": "com.xx.xx", // appid,‘com.xxx.xxx’格式
"productName": "appname", // 应用的名称
"directories": {
"output": "dist" // 打包存在哪个文件夹,这么写的话打包好的exe就会生成在dist中
},
"publish": [ // 配合electron-updater来用
{
"provider": "generic", // 服务器供应商
"url": "http://oss.poooli.com/download/app/desktop/" //服务器地址
}
],
"files": [
"src/resources" // 在这里可以自定义打包文件
],
"nsis": {
"oneClick": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"installerIcon": "src/resources/icons/icon.ico",
"uninstallerIcon": "src/resources/icons/icon.ico",
"installerHeaderIcon": "src/resources/icons/icon.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "name"
},
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "src/resources/icons/icon.icns"