Do you bundle your JS files for performance?


#1

Hi,

In light of this tweet I was wondering if and how any of you bundle the JS files that make up your Electron app:

https://twitter.com/TheLarkInn/status/934651853555449857

I’ve looked around and I haven’t been able to find much more info on how to do this. Bundlers are generally designed to work with browser-based code. And Googling returns a bunch of info on “electron packaging”, which is a different thing.

Thanks.


#2

Electron can be used just like a browser (create BrowserWindow, point it at an HTML file that links to JavaScript, done), so the standard bundling setups can be used for most of the application code (what runs inside the renderer processes).


#3

Right, just realized webpack has a special target for electron (two actually):

https://webpack.js.org/configuration/target/

So that’s straightforward enough.

I’m still wondering how many devs with Electron apps in production actually do this.


#4

The issue is that some bundlers replace core node modules with browser-friendly versions, which can lead to unexpected behavior.

In Electron Renderer you’re neither in pure browser environment or pure node environment. So it requires some consideration before using a bundler. Glad to find webpack has us covered.