相比较于electron-packager打包,使用electron-builder打包使得包体积更小。在electron-builder中,对于NSIS的配置,也是支持的
electron-builder中nsis如何设置:https://www.electron.build/configuration/nsis
本片文章,将会详细阐述几点需要注意的地方。
1,electron-builder打包路径和开发路径不一致。
2,electron-builder打包中若需要对专门的文件有读写的权限,则应将文件加入到asarUnpack数组中 。
3,在“build”属性中需要设置一个属性:"extends": null(具体原因这方面还没有琢磨清楚),可能是由于NSIS本身的属性,不需要去继承。都是用户自定义配置。
,
"asarUnpack": ["./test.txt","./test.ico"
],
"files": [
"./main.js",
"./build${/*}",
"./node_modules${/*}",
"./src${/*}",
"./public${/*}","./test.ico",
"./test.txt"
],
"win": {
"target": [
"nsis",
"zip"
],
"icon": "./satellite.png"
},
"nsis": {
"oneClick": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"installerIcon": "./test.ico",
"uninstallerIcon": "./test.ico",
"installerHeaderIcon": "./test.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"perMachine": true,"unicode": true
},
"extends": null
}
以上是关于build的完整配置,从配置中,可以看到,我们需要对“test.txt”进行操作,所以将,这个文件放到asarUnpack下。