app.asar size is huge with electron-builder 22.11.8
See original GitHub issue- Electron-Builder Version: 22.11.8
- Node Version: v16.4.1
- Electron Version: 13.1.6
- Electron Type (current, beta, nightly): current
- Target: win64
I use electron-builder --dir to create a package.
After changing electron-builder in devDependencies from latest to next, the size of my app.asar is huge. With latest/22.11.7 it is around 35MB. With next/22.11.8 it is around 70MB, and there is an additional directory app.asar.unpacked of 311MB (it contains folders 7zip-bin, app-builder-bin and electron.
When setting asar to false, the node_modules inside resources/app changes from 20MB to 342MB.
Could it be all devDependencies are packaged as well?
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How to reduce electron apps size - Stack Overflow
I tried to unpack the dmg file to see what makes it so big then found a file called app. asar that takes...
Read more >Common Configuration - electron-builder
masDev MasConfiguration - MAS (Mac Application Store) development options ... which specifies which files to unpack when creating the asar archive.
Read more >electron-builder - npm
A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out ......
Read more >electron builder not allowed to load local resource - You.com
I have a small electron app that loads the main.js and main.htm from an /app subfolder. The main.js loads fine and the application...
Read more >Electron packager tutorial - Christian Engvall
Got my first electron app to build easily. I noticed that the output is 144MB. Very large for a simple app. Any advice...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m trying to expand our current unit tests to cover and resolve this. Currently, I’ve added
"node_modules/test.txt"to the correspondingignoreTest.tstests. If you’re willing to give it a shot, here’s the patch I’m running with for unit tests. Then I’m also using it withelectron-quick-startrepo with the config that @MaartenBent provided (thank you!).patch.diff
diff --git a/test/src/ignoreTest.ts b/test/src/ignoreTest.ts index 5452b3eb..3e7b40c0 100644 --- a/test/src/ignoreTest.ts +++ b/test/src/ignoreTest.ts @@ -114,7 +114,8 @@ test.ifDevOrLinuxCi( targets: Platform.LINUX.createTarget(DIR_TARGET), config: { asar: false, - includeSubNodeModules: false // defaults to false too + includeSubNodeModules: false, + files: ["**/*", "node_modules/test.txt"], }, }, { @@ -127,12 +128,14 @@ test.ifDevOrLinuxCi( ...data.dependencies, } }), + outputFile(path.join(projectDir, "node_modules", "test.txt"), "data"), outputFile(path.join(projectDir, "node_modules", "submodule-1-test", "node_modules", "package.json"), "{}"), outputFile(path.join(projectDir, "node_modules", "submodule-2-test", "node_modules", "package.json"), "{}"), ]) }, packed: context => { return Promise.all([ + assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "test.txt")).isFile(), assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules")).doesNotExist(), assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-2-test", "node_modules")).doesNotExist(), ]) @@ -148,7 +151,8 @@ test.ifDevOrLinuxCi( targets: Platform.LINUX.createTarget(DIR_TARGET), config: { asar: false, - includeSubNodeModules: true + includeSubNodeModules: true, + files: ["**/*", "node_modules/test.txt"] }, }, { @@ -161,12 +165,14 @@ test.ifDevOrLinuxCi( ...data.dependencies, } }), + outputFile(path.join(projectDir, "node_modules", "test.txt"), "data"), outputFile(path.join(projectDir, "node_modules", "submodule-1-test", "node_modules", "package.json"), "{}"), outputFile(path.join(projectDir, "node_modules", "submodule-2-test", "node_modules", "package.json"), "{}"), ]) }, packed: context => { return Promise.all([ + assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "test.txt")).isFile(), assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules")).isDirectory(), assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-2-test", "node_modules")).isDirectory(), ]) @@ -182,10 +188,7 @@ test.ifDevOrLinuxCi( targets: Platform.LINUX.createTarget(DIR_TARGET), config: { asar: false, - files: [ - "**/*", - "*/submodule-1-test/node_modules/**", - ], + files: ["**/*", "**/submodule-1-test/node_modules/**"], }, }, { @@ -198,14 +201,18 @@ test.ifDevOrLinuxCi( ...data.dependencies, } }), + outputFile(path.join(projectDir, "node_modules", "test.txt"), "data"), outputFile(path.join(projectDir, "node_modules", "submodule-1-test", "node_modules", "package.json"), "{}"), outputFile(path.join(projectDir, "node_modules", "submodule-2-test", "node_modules", "package.json"), "{}"), ]) }, packed: context => { return Promise.all([ + assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "test.txt")).doesNotExist(), assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules")).isDirectory(), - assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules", "package.json")).isFile(), + assertThat( + path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-1-test", "node_modules", "package.json") + ).isFile(), assertThat(path.join(context.getResources(Platform.LINUX, archFromString(process.arch)), "app", "node_modules", "submodule-2-test", "node_modules")).doesNotExist(), ]) },Related: I use an alias for syncing my electron builder output to my local project instead of yalc. Seems to provide more consistent results
This doesn’t work. The
*.nodefiles are not included anymore since the order matters, see this description. And all the other extra files are still there.It seems as soon as there is a not-ignore pattern containing
node_modules, all the files are being packaged. For example, adding"node_modules/test.txt"anywhere infilestriggers the problem.The only work-around I found so far is not using
"**/node_modules/**/build/Release/*.node"and use this instead:Looks like it is. I can simplify the test case with
electron-quick-startto just