What Is Electron and How It Packages Desktop Apps
Electron is an open-source framework that enables developers to build cross-platform desktop applications using web technologies like JavaScript, HTML, and CSS. This article explains the core architecture of Electron, how it bridges web code with native desktop operating systems, and the step-by-step process of packaging and distributing JavaScript applications into standalone executable files for Windows, macOS, and Linux.
What is Electron?
Electron combines two core technologies into a single runtime:
- Chromium: The open-source rendering engine behind Google Chrome, responsible for displaying user interfaces and executing client-side web code.
- Node.js: A JavaScript runtime that grants access to local operating system resources, such as the file system, hardware, and network interfaces.
By embedding both components, Electron allows developers to write an application using modern web frameworks (like React, Vue, or standard JavaScript) while retaining full access to low-level operating system APIs that are typically unavailable within a standard web browser.
The Electron Architecture
Electron applications run using a multi-process architecture:
- The Main Process: Runs a full Node.js environment and acts as the entry point of the application. It manages native elements such as window lifecycles, application menus, tray icons, and system dialogs.
- The Renderer Process: Each application window opened by the main process is a separate Chromium web page running its own renderer process. It handles the UI rendering and front-end logic.
- Inter-Process Communication (IPC): Because the
renderer process is sandboxed for security, Electron provides IPC
modules (
ipcMainandipcRenderer) allowing the UI and the Node.js backend to exchange messages safely.
How Electron Packages JavaScript Applications
Packaging an Electron app converts raw source code, assets, and dependencies into self-contained, platform-specific binaries.
1. Source Archiving with ASAR
During packaging, your JavaScript, HTML, CSS, and
node_modules are typically packed into an ASAR
(Atom Shell Archive) file. An ASAR archive is a tar-like format
that concatenates all application files into a single flat file. This
mitigates performance issues related to reading thousands of small files
from the disk and prevents the source code from being directly exposed
in plain text folders.
2. Runtime Bundling
The packaging tool downloads a precompiled version of the Electron binary specifically matching the target operating system (Windows, macOS, or Linux) and CPU architecture (x64, arm64). The generated ASAR archive and your application metadata (icons, version info, application name) are injected into the Electron runtime executable directory.
3. Packaging and Distribution Tools
Developers automate the build and packaging pipeline using specialized tools:
- Electron Forge: An all-in-one tool maintained by the Electron team that handles initialization, development, and packaging using customizable templates and plugins.
- electron-builder: A widely used, comprehensive packaging tool that automates building cross-platform installers, auto-updating functionality, and asset compression.
- electron-packager: A lower-level packaging tool that generates the basic executable folder structure without creating full installer packages.
4. Generation of Platform-Specific Installers
The packaging tool compiles the bundled binary into native distribution formats:
- Windows: Generates
.exefiles, NSIS installers, or.msienterprise packages. - macOS: Generates
.appbundles,.dmgdisk images, or.pkginstallers. - Linux: Generates
.AppImage,.deb,.rpm, or Snap packages.
5. Code Signing
As a final step in the packaging process, tools integrate with platform-specific code signing certificates (such as Apple Developer Certificates or Microsoft Authenticode). Code signing proves the application’s authenticity and prevents security warnings like Windows SmartScreen or macOS Gatekeeper from blocking user installation.