Electron — Build Cross-Platform Desktop Apps with Web Tech
Electron is a framework for building cross-platform desktop apps with JavaScript, HTML, and CSS. Powers VS Code, Slack, Discord, Notion, Figma, GitHub Desktop, and many other household apps. Chromium + Node.js bundled together.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 70e59e04-35a3-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
Electron is a framework maintained by the OpenJS Foundation (originally created by GitHub) for building native desktop applications using web technologies. It bundles Chromium for rendering and Node.js for system access into a single runtime, letting you ship one codebase to Windows, macOS, and Linux.
It powers many widely-used applications including VS Code, Slack, Discord, Notion, Figma desktop, and GitHub Desktop. Developers already comfortable with JavaScript, TypeScript, React, or Vue can build desktop apps without learning platform-specific APIs.
How it saves time or tokens
Without Electron, shipping a desktop app to three operating systems means maintaining three separate codebases (or learning a cross-platform toolkit like Qt). Electron eliminates this by reusing your existing web development skills and npm ecosystem. A team that already has a web app can wrap it in Electron and ship a desktop version in days rather than months.
For AI-powered desktop tools, Electron provides direct access to the filesystem and local processes through Node.js, making it straightforward to build local LLM interfaces, file-processing agents, or developer tools that need OS-level access.
How to use
- Scaffold a new Electron project with the quick-start template:
npm create @quick-start/electron@latest my-app
cd my-app
npm install
npm run dev
- Edit the main process file to create your browser window and load your UI.
- Build distributable packages for all platforms using electron-builder or electron-forge.
Example
Minimal main process that opens a window:
const { app, BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: { preload: __dirname + '/preload.js' },
});
win.loadFile('index.html');
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => app.quit());
This creates a 1200x800 window loading a local HTML file with a preload script for secure IPC.
Related on TokRepo
- Coding Tools -- AI-assisted development tools that complement desktop app workflows
- Automation Tools -- Automate build pipelines and releases for Electron apps
Common pitfalls
- Bundle size is large by default (Chromium alone adds 100MB+). Use electron-builder's compression and consider lazy-loading heavy modules to reduce download size.
- Security: never enable
nodeIntegrationin the renderer process. Use the preload script withcontextBridgeto expose only the APIs your renderer needs. - Memory usage can grow quickly with multiple windows. Profile with Chrome DevTools (built into Electron) and close unused windows promptly.
常见问题
A minimal Electron app is roughly 120-150MB uncompressed because it bundles Chromium and Node.js. Compressed installers are typically 50-70MB. This is the main trade-off for cross-platform reach with web technologies.
Use the electron-updater module (part of electron-builder) or Electron's built-in autoUpdater API. Both support Squirrel-based updates on macOS and Windows. You host update files on a static server, S3, or GitHub Releases.
Yes. The main process has full Node.js filesystem access. The renderer process should access files through IPC calls to the main process for security. Use the dialog module to open native file picker dialogs.
Tauri uses the OS native webview instead of bundling Chromium, resulting in much smaller binaries (under 10MB). However, Tauri requires Rust knowledge for the backend and has less mature ecosystem tooling. Electron has a larger community and more battle-tested in production.
Electron apps consume significant memory (typically 100MB+) because of the Chromium runtime. For IoT or embedded use cases, lighter alternatives like Tauri or native toolkits are better choices. Electron targets standard desktop hardware.
引用来源 (3)
- Electron GitHub— Electron bundles Chromium and Node.js for cross-platform desktop apps
- Electron Official Site— Electron is maintained by the OpenJS Foundation
- Electron Security Documentation— Security best practices for Electron apps including contextBridge
讨论
相关资产
Avalonia — Cross-Platform .NET UI Framework for Desktop, Mobile & Web
A cross-platform UI framework for .NET that lets you build apps for Windows, macOS, Linux, iOS, Android, and WebAssembly from a single C# and XAML codebase.
Wails — Build Desktop Apps with Go and Web Technologies
Wails lets you create beautiful desktop applications using Go for the backend and any web frontend. Uses the OS native WebView (like Tauri) producing ~8MB binaries. No Electron bloat, full Go power, and access to native APIs via bindings.
Quasar Framework — Vue.js Components for Web, Mobile, Desktop, and Electron
A high-performance Vue.js framework with 70+ components that can target SPAs, SSR, PWAs, mobile apps via Capacitor/Cordova, desktop via Electron, and browser extensions from one codebase.
Wry — Cross-Platform WebView Rendering Library for Rust
A Rust library for creating cross-platform desktop applications with web-based UIs by leveraging each operating system's native webview engine with minimal overhead.