如何减小超过600 mb的电子封装尺寸

时间:2019-07-05 18:12:27

标签: javascript electron package.json electron-builder electron-packager

我看到这是因为节点模块和应用程序打包了一些不需要的东西以便运行。当前文件大小为600 mb,但我希望它小于200 mb。

我怀疑--no-prune会填充所构建软件包中的所有节点模块,但是我只需要在所构建软件包中指定节点模块

我尝试删除package.json中不需要的软件包,这也无济于事

重构后

 "bundledDependencies": [

    "fs",

    "os",
    "path",

    "regedit",
    "request",
    "start",
    "xml2js",
    "util",
    "replace",
    "process",
    "fs",
    "console"

  ],
**before refactoring**
 "bundledDependencies": [
    "archiver",
    "child_process",
    "fs",
    "node-wget",
    "os",
    "path",
    "ping",
    "regedit",
    "request",
    "start",
    "xml2js",
    "util",
    "replace",
    "process",
    "fs",
    "console",
    "electron",
    "electron-builder",
    "electron-packager"
  ],

这也没有帮助我

package.json

{
  "productName": "xyz",
  "description": "something",
  "version": "1.0.1",
  "main": "main.js",
  "scripts": {
    "start": "electron .",

    "builderForWindows": "electron-packager --out winx64 --overwrite --platform win32 --appname clientsettings . --executable-name abc --no-prune",
    "builderForLinux": "electron-packager --out Linx64 --overwrite --platform linux --appname clientsettings .  --executable-name abc --no-prune"
  },
  "author": "xyz",
  "devDependencies": {
    "archiver": "^2.1.1",
    "asar": "^2.0.1",
    "child_process": "^1.0.2",
    "console": "^0.7.2",
    "electron": "^4.0.4",
    "electron-builder": "^20.41.0",
    "electron-packager": "^13.1.1",
    "fs": "0.0.1-security",
    "node-wget": "^0.4.2",
    "os": "^0.1.1",
    "path": "^0.12.7",
    "ping": "^0.2.2",
    "regedit": "^3.0.2",
    "replace": "^1.1.0",
    "replace-in-file": "^4.1.0",
    "request": "^2.85.0",
    "start": "^5.1.0",
    "xml2js": "^0.4.19"
  },
  "bundledDependencies": [
    "archiver",
    "child_process",
    "fs",
    "node-wget",
    "os",
    "path",
    "ping",
    "regedit",
    "request",
    "start",
    "xml2js",
    "util",
    "replace",
    "process",
    "fs",
    "console",
    "electron",
    "electron-builder",
    "electron-packager"
  ],
  "dependencies": {
    "appdata-path": "^1.0.0",
    "targets": "^1.11.0"
  }
}

1 个答案:

答案 0 :(得分:3)

  

App Bundle有一些不必要的节点   模块(例如:electron-packager,electron-builder),为什么需要它们   捆绑后,如何摆脱它们?

“ bundledDependencies”中列出的所有内容都将包含在应用程序捆绑包中。

  "builderForWindows": "electron-packager --out winx64 --overwrite --platform
 win32 --appname clientsettings . --executable-name abc --no-prune",

return Stack(
  children: <Widget>[
    new charts.PieChart(
      _project.getExpensesToChartSeries(),
      animate: animate,
      animationDuration: Duration(milliseconds: 500),
      selectionModels: [
        new charts.SelectionModelConfig(
          type: charts.SelectionModelType.info,
          changedListener: _onSelectionChanged,
      defaultRenderer: new charts.ArcRendererConfig(arcWidth: 25),
    ),
    Center(child: Text("bla bla")),
  ],
);

指定“禁止修剪” –请参阅以下答案:https://stackoverflow.com/a/44156640/840992

  

请注意不要在最终应用程序中包含不需要的node_modules。如果将它们放在   package.json,默认情况下,与这些模块都不相关的模块   依赖项将复制到应用程序捆绑包中。 (此行为可以是   通过--no-prune标志关闭。)

在电子包装器API页面上有关--prune标志的信息

  

运行程序包管理器命令从以下位置删除package.json的devDependencies部分中指定的所有程序包:   输出的电子应用程序。