7

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

Arun Krishnan
  • 211
  • 1
  • 3
  • 10
  • I think @MertSimsek's answer is correct since right now your packaging everything in your `devDependencies` which are all big packages – Joshua Dec 18 '17 at 12:04
  • 6
    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. – Arun Krishnan Dec 19 '17 at 14:08
  • 1
    After rebuilding, my application now comes to 39MB which is way better :-) – Arun Krishnan Dec 19 '17 at 14:50
  • @ArunKrishnan how did you change output folder? – msdos Aug 02 '19 at 04:50
  • 1
    You can change that in the package.json file. ` "scripts": { "build": "electron-packager . --platform win32 --arch x64 --out ` 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. – Arun Krishnan Sep 06 '19 at 07:19

3 Answers3

10

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

Mert Simsek
  • 1,550
  • 9
  • 19
  • 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? – Arun Krishnan Dec 19 '17 at 14:10
  • Looks like it removed a whole bunch of packages and had to reinstall them and then build. Works now. Thanks for your help. – Arun Krishnan Dec 19 '17 at 14:50
1

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!

Peter Jaric
  • 5,162
  • 3
  • 30
  • 42
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
Franco
  • 441
  • 3
  • 18
  • 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" – Franco Aug 18 '23 at 08:59