Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

electron package: reduce the package size

I made a simple Electron app:

main.js

const {app, BrowserWindow} = require('electron') const path = require('path') const url = require('url')  let win  function createWindow () {   win = new BrowserWindow({     width: 800,      height: 600,      icon: path.join(__dirname, 'icon.ico')   })    win.maximize();    win.loadURL('https://stackoverflow.com/', {"extraHeaders" : "pragma: no-cache\n"});    win.on('closed', () => {     win = null   }) }  app.on('ready', createWindow)  app.on('browser-window-created',function(e,window) {     window.setMenu(null); });  app.on('window-all-closed', () => {   if (process.platform !== 'darwin') {     app.quit()   } })  app.on('activate', () => {   if (win === null) {     createWindow()   } }) 

package.json

{   "name": "test",   "version": "1.0.0",   "main": "main.js",   "build": {     "appId": "com.test.app",     "copyright": "test",     "productName": "test"   },   "devDependencies": {     "electron": "1.7.9",     "electron-builder": "^19.46.4",     "electron-packager": "^10.1.0"   } } 

with electron-packager i have builded the package to release:

electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --prune=true --out=release-builds 

the total size of the builded package is 107 MB.

Anyone have tips to reduce the size of the package?

like image 797
ar099968 Avatar asked Dec 01 '17 16:12

ar099968


People also ask

Why is my Electron app so large?

Electron applications consume a lot of disk space because each application is bundled with Chromium and Node. On the other hand, Tauri and Neutralino. js have surprisingly lightweight bundle sizes because those frameworks are reusing the user's operating system's system web browser library.

How large is an Electron app?

Because Electron is essentially a “browser in a box,” every Electron app also comes with the Electron framework, which weighs in at an astonishing 120 MB. Because of how Electron works, you can't install the framework on your computer and then get all the other apps that use Electron to use it.

Why does Electron use so much memory?

Electron will use a ton of memory because it's running a full browser inside a browser/desktop, Chromium, along with running v8 and all of it's own code. Along with that Chromium is already known for high memory usage. So it's relatively normal to see high memory.

How to reduce the size of an electron app?

(Nginx tutorial) You can reduce the electron app size by packaging using electron-builder package. PicArt is an electronjs app which I developed recently. It is built using reactJS. Initially when I packaged the app using electron-packager the Window's build size was around 98 MB.

How do I package an electron app?

Packaging an electron app simply means creating a desktop installer (dmg, exe, deb, etc). Now if you decide to go around manually packaging your app, you’re gonna have a bad time. Luckily there are modules, especially the two mentioned below which make the task easier.

Why does my electron app take so much RAM?

Because of that: Size of application built with Electron is typically around ~120 MB. Electron apps usually use a lot of RAM. UI might feel a bit slow, especially on the older computers. Now, even though we can't just delete the whole Chromium from our app and reduce it's size, we can still do something about the RAM usage & speed.

What are the downsides of using electron?

Unfortunately, Electron has some downsides. To render your application UI, it uses Chromium, which is always bundled in your final application. Because of that: Size of application built with Electron is typically around ~120 MB. Electron apps usually use a lot of RAM. UI might feel a bit slow, especially on the older computers.


1 Answers

You can reduce the electron app size by packaging using electron-builder package.

PicArt is an electronjs app which I developed recently. It is built using reactJS. Initially when I packaged the app using electron-packager the Window's build size was around 98 MB. Then I found this awesome boilerplate electron-react where they configured the electron-builder to produced optimised build size. After using those configuration setup, PicArt's build is now around 36 MB.

Yes, it is possible to reduce the app size , but it quite painful and time consuming to configure the build setup.

like image 125
Bharathvaj Ganesan Avatar answered Sep 20 '22 23:09

Bharathvaj Ganesan