gpt4 book ai didi

javascript - 如何减小超过 600 MB 的 Electron 封装大小

转载 作者:太空宇宙 更新时间:2023-11-04 01:27:45 24 4
gpt4 key购买 nike

我发现这是因为节点模块和应用程序打包了一些不需要的东西来运行。当前文件大小为 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"
}
}

最佳答案

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?

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

  "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",

指定“不 trim ” – 请参阅此答案: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.)

来自 Electron-packager API 页面关于 --prune 标志的信息

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

关于javascript - 如何减小超过 600 MB 的 Electron 封装大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56933214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com