Electron-builder构建MSI安装包时asar文件过大的问题求助
Angular + Electron 打包MSI时asar文件过大的问题求助
我有一个Angular应用,需要创建MSI安装包。已成功运行electron应用(执行npm run electron),但创建安装包时遇到如下错误:
error LGHT0263 : 'C:...\release\win-unpacked\resources\app.asar' is too large, file size must be less than 2147483648.
执行命令的顺序如下:
npm run electron→ 运行electron应用验证功能(后续步骤前已关闭应用)npm run tscnpm run step2npm run electron:build
我猜测是electron-builder.json中包含了过多文件,但由于是首次使用electron和electron-builder,不确定哪些文件可移除、哪些是应用运行必需的。
当在electron-builder.json中设置"asar": false时,MSI安装包可以生成,但会收到警告asar usage is disabled — this is strongly not recommended,构建耗时极长(约30分钟),且MSI包大小接近1.5GB。
请问如何减小asar文件的大小?
项目结构
|- dist |- electron |- main.ts |- package.json |- node_modules |- release |- src |- all angular source code |- angular.json |- electron-builder.json |- package.json |- tsconfig.json |- tsconfig.serve.json
package.json 脚本
"scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "electron": "ng build --configuration electron && electron .", "tsc": "tsc -p tsconfig.serve.json", "step2": "ng build --base-href ./ --configuration electron", "electron:build": "electron-builder build --publish=never" }
electron-builder.json
{"asar": true, "directories": { "output": "release/" }, "files": [ { "from": "dist", "filter": ["**/*"] }, { "from": "electron", "filter": ["**/*"] }, { "from": "src", "filter": ["**/*"] }, "!**/*.ts", "!*.map", "!package.json", "!package-lock.json", "!node_modules/**", "!.angular/**", "!.vscode/**", "!cypress/**", "!release/**" ], "win": { "icon": "offline-test.ico", "target": [ "msi" ] } }
tsconfig.serve.json
{ "compilerOptions": { "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "module": "commonjs", "target": "es2015", "types": [ "node" ], "lib": [ "es2017", "es2016", "es2015", "dom" ] }, "files": [ "electron/main.ts" ], "exclude": [ "node_modules", "**/*.spec.ts" ] }
我已经排查过类似的打包体积过大问题,但目前已经排除了MSI文件所在目录,不确定还能排除哪些内容。
内容的提问来源于stack exchange,提问作者Ada
相关产品推荐
相关产品推荐

