如何减小 Electron 应用程序的应用程序大小? [英] How do I reduce the app size of an Electron app?

查看:38
本文介绍了如何减小 Electron 应用程序的应用程序大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用最新的 Electron 版本 10.0.3 并为 appmas (mac-app-store) 创建了一个目标,我与其创建的应用程序的大小作斗争.

I use the latest Electron version 10.0.3 and created a target for app and mas (mac-app-store) and I struggle with the size of the app it created.

我已经找到了一些涵盖这些主题的博客文章,但是我的应用程序大小异常之大,以至于我无法确定造成这种情况的原因.

I found already a few blog posts which cover the topics, but my app size is so unusually high, that I couldn't pinpoint the cause for my situation.

以下是尺寸列表:

目标:app

  • 电子框架 (130 MB)
  • app.asar (462 MB)

目标:mas:

  • 电子框架 (130 MB)
  • app.asar (1.1GB)

请注意,在 mas 构建中,app.asar 的大小是原来的两倍.首先我假设它现在也可以为新的 arm64 架构编译,但它只是 x86_64.这些巨大的应用程序大小可能是什么原因,以及为什么 mas 的大小是原来的两倍?

Please note, that in the mas build the app.asar is double the size. First I assumed it now also compiles for the new arm64 architecture, but it's just the x86_64. What could be the reason for these huge app sizes, and why is mas double the size?

推荐答案

asar 存档的大尺寸很可能与您正在使用的节点模块有关

The big size of the asar archive is most likely related to the node modules you are using

你可以像这样提取app.asar

You can extract app.asar like this

npx asar extract app.asar dest

然后,您可以在提取的文件夹上使用 WinDirStat 之类的工具来确定最有罪的模块,您也许可以删除或替换它们

Then you can use a tool like WinDirStat on the extracted folder to determine the guiltiest modules and you can perhaps remove or replace them

您还可以在打包前使用 modclean 来删除有时包含在某些文件中的不需要的垃圾模块

You can also use modclean before packaging to delete unneeded junk that sometimes is included in some modules

另外,请确保将仅在开发中需要的模块安装为 devDependencies,以便 electron-builder 不会打包它们.electron 例如,应该在 devDependencies

Also, make sure to install modules that are only needed in development as devDependencies so that electron-builder won't package them. electron for example, should be in devDependencies

这篇关于如何减小 Electron 应用程序的应用程序大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆