By contrast, compiled code is converted to binary — the language that the computer processor speaks. This is how applications created with most “professional” programming languages are distributed. The source code is not distributed with the application. It is impossible for another developer to open the binary and recreate the source which created it. Generally speaking, binary code is hidden and protected.
Can we create JS binaries for Electron?
As you may have guessed: Yes!
- Bytenode needs access to Node.js’ V8 functions in order to read the binaries. This will work just fine for your main process and any preload scripts. But you’ll need to enable
document.addEventListener('DOMContentLoaded')listener. You’ll also need to set
contextIsolationto false, or come up with a more elegant workaround.
- There are a few known issues with Bytenode. The main one to be aware of is that asynchronous arrow functions will cause crashes when used in rendering process code. You can simply convert these to
functioncalls, or you could code in Typescript and output ES5, or you could use the Webpack babel-loader plugin to transform your arrow functions.
- It looks like Electron is deprecating Node’s V8 library in the render process beginning with Electron 12. Bytenode still works for now, but we’re be keeping an eye on this.
How do I get started?
I’ve created an Electron Bytenode Example repository on GitHub. Start there! It uses Electron Forge along with Webpack to bundle applications suitable for distribution. Follow the README instructions and you should be up and running quickly.
- Electron Bytenode Example — a boilerplate “Hello World” example of an Electron app running on Bytenode, built with Webpack via Electron Forge
- Bytenode Webpack Plugin — the Webpack plugin which makes all of this easy
We think we’ve ironed out most of the kinks, but if you find issues with any of these packages, please submit issues. Or better yet, create a pull request and contribute!
When I started developing a commercial Electron application, this was the missing piece of the puzzle. How do you distribute your application without distributing its source code? Now we have an easy-to-implement solution! I’m really proud of what we’ve built and I’m happy to share it with the Electron development community.
Jeff Robbins is a business coach, mentor, and virtual business partner who works one-on-one with company owners and leaders to help them build vision and direction for their companies while building productivity, stability, and happiness for their employees and themselves. You can work with him too. Reach out to set up a free consultation session.