electron

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Electron

Electron

Electron bundles Chromium and Node.js into a desktop app. It is the industry standard (VS Code, Slack, Discord) despite the file size.
Electron将ChromiumNode.js打包成一个桌面应用程序。尽管文件体积较大,但它仍是行业标准方案(如VS Code、Slack、Discord均基于此开发)。

When to Use

适用场景

  • Rich Capabilities: If you need full Node.js access (Filesystem, Serial Port).
  • Consistent UI: Loops exactly the same on Windows/Mac/Linux (Pixel Perfect).
  • Legacy: Migrating an existing web app to desktop with zero changes.
  • 丰富功能支持:如果您需要完整的Node.js权限(如文件系统、串口访问)。
  • UI一致性:在Windows/Mac/Linux系统上呈现完全一致的界面(像素级完美)。
  • 遗留项目迁移:无需任何改动即可将现有Web应用迁移为桌面应用。

Core Concepts

核心概念

Main Process

主进程

The Node.js backend. Controls lifecycle and windows.
Node.js后端,负责控制应用生命周期和窗口管理。

Renderer Process

渲染进程

The Chromium frontend. Displays UI.
Chromium前端,负责展示用户界面。

Preload Scripts

预加载脚本

The secure bridge between Main and Renderer (Context Isolation).
主进程与渲染进程之间的安全桥梁(上下文隔离机制)。

Best Practices (2025)

2025年最佳实践

Do:
  • Enable Context Isolation: Critical security feature (
    contextIsolation: true
    ).
  • Use IPC:
    ipcMain
    and
    ipcRenderer
    for communication.
  • Update Chromium: Security patches come via Electron updates.
Don't:
  • Don't use
    remote
    module
    : It is deprecated and insecure.
推荐做法
  • 启用上下文隔离:这是至关重要的安全特性(配置
    contextIsolation: true
    )。
  • 使用IPC通信:通过
    ipcMain
    ipcRenderer
    实现进程间通信。
  • 更新Chromium版本:通过Electron更新获取安全补丁。
不推荐做法
  • 避免使用
    remote
    模块
    :该模块已被废弃且存在安全风险。

References

参考资料