How to reduce Electron package size that exceeds more than 600 mb

前端 未结 1 1176
醉话见心
醉话见心 2021-01-28 23:54

I see this is because of node-modules and application is packaged with some unwanted stuffs for running. Current file size is 600 mb but I want it to be less than 200 mb.

<
1条回答
  •  有刺的猬
    2021-01-29 00:33

    App Bundle has some unnecessary node modules(ex:electron-packager,electron-builder),why do I need them after its bundled, how to get rid of them?

    Everything listed in "bundledDependencies" will be included in the app bundle.

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

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

    Specifying "no prune" – see this answer: https://stackoverflow.com/a/44156640/840992

    Be careful not to include node_modules you don't want into your final app. If you put them in the devDependencies section of package.json, by default none of the modules related to those dependencies will be copied in the app bundles. (This behavior can be turned off with the --no-prune flag.)

    From electron-packager API page about --prune flag

    Runs the package manager command to remove all of the packages specified in the devDependencies section of package.json from the outputted Electron app.

    0 讨论(0)
提交回复
热议问题