electron builder app size is too large
Asked Answered
P

3

10

I find that the MyApp.exe file generated using electron-builder is nearly about 500M. I am not sure what I did because previously, just for ia32 or x64, it would be around 196M. I also looked at this link and it mentions only about 55MB-60MB. So the question is, why am I getting such large sizes for my exe files? My app itself is very small and if electron is only around 33MB, what's all that extra space there?

Here are my package.json entries:

"build": {
"appId": "com.electron.myApp",
"publish": [
  {
    "provider": "generic",
    "url": "https://myAppServer"
  }
],
"win": {
  "target": [
    {
      "target": "nsis",
      "arch": [
        "ia32"
      ]
    }
  ]
},
"asar": false,
"nsis": {
  "oneClick": true,
  "perMachine": false,
  "artifactName": "${productName}-Setup-${version}.${ext}"

}    
"devDependencies": {
 "electron": "^1.7.9",
 "electron-installer-windows": "^0.2.0",
 "electron-builder": "^19.45.5",
 "electron-packager": "^8.5.2",
 "electron-winstaller": "^2.5.2",
 "grunt-electron-installer": "^2.1.0"
},
"dependencies": {
 "auto-launch": "^5.0.1",
 "cron": "^1.2.1",
 "electron-config": "^0.2.1",
 "electron-positioner": "^3.0.0",
 "electron-squirrel-startup": "^1.0.0",
 "electron-window": "^0.8.1",
 "electron-updater": "^2.16.1",
 "fs": "^0.0.1",
 "homedir": "^0.6.0",
 "https": "^1.0.0",
 "https-proxy-agent": "^1.0.0",
 "line-by-line": "^0.1.5",
 "pac-proxy-agent": "^1.0.0",
 "url": "^0.11.0",
 "winreg": "^1.2.3",
 "xml2js": "^0.4.17"
} 
}

Is this the expected size of an electron app? Any way to make this smaller?

Regards, Arun

Psychosis answered 18/12, 2017 at 10:30 Comment(5)
I think @MertSimsek's answer is correct since right now your packaging everything in your devDependencies which are all big packagesLamond
I figured out what the issue was. I had an Output directory within my electron root directory where I was storing my final MSI files. It was packaging that directory as well as a result of which the size kept growing.Psychosis
After rebuilding, my application now comes to 39MB which is way better :-)Psychosis
@ArunKrishnan how did you change output folder?Onetime
You can change that in the package.json file. ` "scripts": { "build": "electron-packager . <package name> --platform win32 --arch x64 --out <Build directory name> ` This should work. Also, before any new build, ensure your build directory is clean. That way you will be guaranteed to not have older versions also bundled up.Psychosis
P
10

You can try npm prune --production but even the most minimal Electron application is going to be around 100MB.

Phonolite answered 18/12, 2017 at 10:34 Comment(2)
I used this and it seems to have broken something. Now when I run "npm run dist" I get a lot of errors starting with TypeError: t.toLowerCase is not a function. Not sure what went on. Has it removed some packages required?Psychosis
Looks like it removed a whole bunch of packages and had to reinstall them and then build. Works now. Thanks for your help.Psychosis
R
2

I'm going to turn Arun's comment into an answer because I nearly missed it, and it was what solved the issue for me:

I figured out what the issue was. I had an Output directory within my electron root directory where I was storing my final MSI files. It was packaging that directory as well as a result of which the size kept growing.

Thanks, Arun!

Rhinestone answered 25/5, 2022 at 18:4 Comment(3)
How did you do that?Salutation
I honestly don't remember, but in package.json I have build.win.files set to an array which include "!**/dist". That may be it, but I'm not sure.Rhinestone
Yes you were correct. See my answer that I postedSalutation
S
0

You should tell electron builder to only use your built files which was generated by

ng build --configuration production

To do this use the files parameter inside your build parameter in your package.json:

"files": [
        "!*.*",
        "!**/*",
        "dist/YourApp/**/*"
    ],
  • The 1st value exludes all files in root directory of your project
  • The 2nd value exludes all subdirectories in root directory of your project
  • List 3rd value only includes your built code
Salutation answered 18/8, 2023 at 8:53 Comment(1)
Note: When you target both 32 and 64 architectures your installer will be double the size than just with 1. Although in the question the person is only targeting 1 architecture, i.e. "ia32"Salutation

© 2022 - 2024 — McMap. All rights reserved.