将电子应用程序打包为可安装或可执行的。 electron-builder 应该是最好的选择。而且它很容易配置,我们也可以使用电子自动更新器。这里是electron-builder.json的例子
{
"publish": {
// This can be also 's3', 'github'... based on which server you are using for publish
// https://www.electron.build/configuration/publish
"provider": "generic",
// Feed URL but github provider case, other fields will be required. 'repo', 'owner'...
"url": "https://myappserver.com/updates/"
},
"productName": "My App",
"appId": "com.myapp.app",
"directories": {
// The icon and background in 'buildResources' will be used as app Icon and dmg Background
"buildResources": "buildResources",
// output is directory where the packaged app will be placed
"output": "release"
},
// The files which will be packed
"files": ["src/", "node_modules/", "package.json"],
"mac": {
"target": ["dmg", "zip"], // Also can be, 'pkg', ...
"artifactName": "${productName}-${version}-${os}.${ext}"
},
"win": {
"target": ["nsis", "zip"], // Also can be, 'portable', ...
"artifactName": "${productName}-${version}-${os}.${ext}"
},
"linux": {
"target": ["AppImage"],
"artifactName": "${productName}-${version}-${os}.${ext}"
},
"dmg": {
"title": "${productName}-${version}",
"contents": [
{
"x": 300,
"y": 360
},
{
"x": 490,
"y": 360,
"type": "link",
"path": "/Applications"
}
]
}
}
当然,我们也可以添加nsis、extraFiles、afterPack、afterSign等其他配置...
以上都很好用。您可以在此处查看详细信息和其他字段https://www.electron.build/configuration/publish
我们可以在package.json内部定义这个配置,或者作为一个独立的文件,但名称应该是electron-builder.json或者electron-builder.yml在项目根目录下。
此外,用于自动更新。
我们应该在zip、blockmap和latest-{OS_Name}.ymlfiles中上传安装程序(dmg、exe、appImage)。