build-electron is a specialized command-line tool designed to simplify the use of ES Modules (ESM) in Electron's main and preload processes. It targets the persistent challenge of Electron's lack of native ESM support by providing a pre-configured Webpack 5 build system, abstracting away complex configurations. It is currently at version 1.0.5 and appears to have an infrequent release cadence, with minor fixes and updates being pushed when needed. Its key differentiator is its focus solely on the Electron main/preload code, intentionally avoiding renderer code to keep the tool simple and framework-agnostic. This allows developers to pair it with existing frontend build tools like Create React App without conflict, aiming for a plug-and-play experience until Electron natively supports ESM. It is not a boilerplate but a build utility.
npm install build-electronNo compatibility data collected yet for this library.
This quickstart demonstrates how to set up `build-electron` for developing and building an Electron application using ES Modules for the main and preload processes, including a basic Electron main entry file and `package.json` scripts.
Utilize `build-electron` or another bundler to transpile your ESM code into a CommonJS compatible format for Electron's runtime.
Integrate a dedicated frontend build tool alongside `build-electron` for your renderer process. Ensure output directories do not conflict and are correctly referenced by Electron.
Always ensure your `mainTarget` and `preloadTarget` in `build-electron.config.js` accurately reflect the major version of Electron you are using in your project.
Define distinct output directories for `build-electron` and other build tools. Update `package.json`'s `main` field and `webPreferences.preload` path in `BrowserWindow` to point to the correct `build-electron` output.
Ensure `build-electron` is configured and executed correctly to process your main and preload files, transforming them into a format Electron can understand (e.g., CommonJS).
Create or verify `build-electron.config.js` in your project root and ensure `mainEntry` and `preloadEntry` are correctly specified with valid paths to your source files.
Install `electron` as a dev dependency (`yarn add -D electron` or `npm install --save-dev electron`) and ensure your `package.json` scripts are correctly set up to use the locally installed binary (e.g., `electron .`).
Check the console output for more specific Webpack or compilation errors that precede this message. Review your source code for syntax issues and verify `build-electron.config.js` for correctness.