What Electron Does
- Main process — Node.js environment, OS APIs (filesystem, network, child processes)
- Renderer process — Chromium window, your web app
- IPC — bridge between main and renderer via
ipcMain/ipcRenderer - Native menus — Menu, MenuItem, Tray, dock icon
- Auto-updater — Squirrel-based updates
- Notifications — native OS notifications
- Power/clipboard/crash reporting — OS-level primitives
- Packaging — electron-builder / electron-forge
Architecture
One main process launches one or more BrowserWindows (renderers). Chromium renders HTML; Node.js runs in main (and optionally renderer via contextIsolation). IPC messages cross the boundary. Security rule: renderer is untrusted, always validate inputs.
Self-Hosting
Package locally then distribute:
npm run build
npx electron-builder --mac --win --linuxDistribute binaries via your site or auto-update server (like Nucleus, Hazel, or GitHub Releases).
Key Features
- Cross-platform (Win/Mac/Linux)
- Full Node.js in main process
- Native menus, tray, notifications
- Auto-updater
- Code signing support
- Crash reporter
- DevTools extensions
- MAS (Mac App Store) signing
- v28+ drops Node 18, uses ESM
Comparison
| Framework | Binary Size | Runtime | Language | Memory |
|---|---|---|---|---|
| Electron | ~150MB | Chromium + Node | JS | ~200MB idle |
| Tauri | ~3-10MB | OS WebView + Rust | Rust + JS | ~80MB idle |
| Neutralino | ~2MB | OS WebView | JS (no Node) | ~50MB |
| NW.js | ~150MB | Chromium + Node | JS | ~200MB |
| Wails | ~8MB | OS WebView + Go | Go + JS | ~80MB |
常见问题 FAQ
Q: 包体积为什么这么大? A: Chromium (~100MB) + Node.js (~30MB) 都打进每个应用。这是跨平台一致性的代价。
Q: 安全问题?
A: 启用 contextIsolation、关闭 nodeIntegration、用 preload 暴露受限 API。禁止执行远程代码。
Q: 何时选 Tauri? A: 追求小体积+性能+Rust 生态时选 Tauri;需要完整 Node 生态或 Chromium 精确一致性时选 Electron。
来源与致谢 Sources
- Docs: https://www.electronjs.org/docs
- GitHub: https://github.com/electron/electron
- License: MIT