Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The file size is abnormal after packaging #66

Open
nanfb opened this issue Jul 4, 2024 · 12 comments
Open

The file size is abnormal after packaging #66

nanfb opened this issue Jul 4, 2024 · 12 comments

Comments

@nanfb
Copy link

nanfb commented Jul 4, 2024

If the code on the main branch is packaged directly, the dist size reaches 1g. This is not normal. Is there any way to optimize it?

@nanfb
Copy link
Author

nanfb commented Jul 9, 2024

If the code on the main branch is packaged directly, the dist size reaches 1g. This is not normal. Is there any way to optimize it?

I tried removing the
image
In this part, the packaging volume has been significantly reduced. I feel that this configuration is unnecessary.
Although there are some file filters, I observed that node_modules will still be generated in the packaged file after packaging, which takes up a lot of space.

@teslor
Copy link

teslor commented Jul 11, 2024

In this part, the packaging volume has been significantly reduced. I feel that this configuration is unnecessary.

I'm also concerned about the size of my app. For example, electron-vue-template nsis installer for Windows is 191MB and the installed app takes up 700MB on disk.
Removing these lines actually reduced the size to 72.3MB and 256MB respectively. However, I had to leave package.json here or the build would fail. The app seems to work fine without issues. I also tried this on my own app.

@Deluze
Copy link
Owner

Deluze commented Jul 11, 2024

The package.json is indeed needed as Electron Builder uses it to fetch some information, like what file to use as an entrypoint.

If the node_modules directory really doesn't need to be copied, we should remove it. I didn't know it took up so much space 😮

@nanfb
Copy link
Author

nanfb commented Jul 11, 2024

The package.json is indeed needed as Electron Builder uses it to fetch some information, like what file to use as an entrypoint.

If the node_modules directory really doesn't need to be copied, we should remove it. I didn't know it took up so much space 😮

Not sure, files are usually packaged, but there are special cases where some libraries cannot be compiled, such as sharp, maybe there should be a list

@Deluze
Copy link
Owner

Deluze commented Jul 11, 2024

Just confirmed that node_modules doesn't have to be copied over to the build folder. Sweet! Makes the build also slightly faster.

Thanks for showing @nanfb :-)

@Deluze
Copy link
Owner

Deluze commented Jul 11, 2024

Pushed a commit that removes this unneeded copy. Thanks @nanfb @nanfb

@Deluze Deluze closed this as completed Jul 11, 2024
@teslor
Copy link

teslor commented Jul 12, 2024

Pushed a commit that removes this unneeded copy

Just checked how it works on my app, and unfortunately these changes cause not all required dependencies to be included in the built app. Removing the "!**/*" filter from the "files" section fixes the issue, the app gets a bit bigger (not that much), but works.

@Deluze
Copy link
Owner

Deluze commented Jul 12, 2024

That's a bit unfortunate...

Removing the "!**/*" filter from the "files" section fixes the issue, the app gets a bit bigger

This would also include the node_modules though, and all other project files that you probably don't want to include in your distributed build.

What dependencies are causing it to break for you?

@Deluze Deluze reopened this Jul 12, 2024
@teslor
Copy link

teslor commented Jul 12, 2024

other project files that you probably don't want to include

Probably, but at least the app works and has reasonable size :) I assume this filter should be tweaked somehow.

What dependencies are causing it to break for you?

My app reports about electron-store dependency (error when run the built app), but it might be just the first one.

@Deluze
Copy link
Owner

Deluze commented Jul 12, 2024

I just checked out the default value for files of electron-builder. I guess we can just copy that instead, to be safe.

@nanfb
Copy link
Author

nanfb commented Jul 12, 2024

您可能不想包含的其他项目文件

可能吧,但至少应用程序可以运行,而且大小合理:)我认为应该对这个过滤器进行某种调整。

哪些依赖关系导致它中断?

我的应用程序报告了有关electron-store依赖性(运行构建的应用程序时出错),但它可能只是第一个。

I said above that some packages cannot be packaged into app.asar. When there is a problem, you need to explicitly filter it, such as sharp, an image processing package. You need to consider these problems.

@teslor
Copy link

teslor commented Jul 16, 2024

I just checked out the default value for files of electron-builder. I guess we can just copy that instead, to be safe.

I see that you've already added these defaults. But I assume it's not needed. I've tested a bit and it seems all default ignores are added implicitly (as those doc says - "All default ignores are added in any case — you don’t need to repeat it if you configure own patterns")
Ignores !build, !dist, !scripts are also unnecessary since we don't have a filter **/* which adds all files, so we don't need to exlude them.

For now, I have come up with the following content for the `files' section, which seems to work fine for my project:

    {
      "from": "build",
      "to": ".",
      "filter": ["**/*"]
    },
    {
      "from": "src/main/static",
      "to": "static",
      "filter": ["**/*"]
    },
    "package.json",
    "!node_modules/**/{CHANGELOG.md,README.md,README,readme.md,readme}",
    "!node_modules/**/{src,demo,test,__tests__,tests,powered-test,example,examples}",
    "!node_modules/**/*.map"

I changed standard ignores for node_modules to use ** instead of * otherwise the files in deeper subfolders will not be excluded.
One thing is unclear, the doc says package.json is added implicitly, but for some reason it should be added explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants