You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 tsc
  • npm run step2
  • npm 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 22:06:15