capacitor-platforms

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Capacitor Platforms (Desktop)

Capacitor 桌面平台

Bring a Capacitor app to macOS, Windows, and Linux with the Capawesome desktop platforms:
@capawesome/capacitor-electron
and
@capawesome/capacitor-tauri
. Both use the standard Capacitor workflow (
cap add
/
cap sync
/
cap run
), report
Capacitor.isNativePlatform()
as
true
, and deliver deep links through the standard
@capacitor/app
events.
借助Capawesome桌面平台,将Capacitor应用部署到macOS、Windows和Linux系统:
@capawesome/capacitor-electron
@capawesome/capacitor-tauri
。两者均采用标准Capacitor工作流(
cap add
/
cap sync
/
cap run
),
Capacitor.isNativePlatform()
会返回
true
,并通过标准
@capacitor/app
事件处理深度链接。

Prerequisites

前置要求

RequirementElectronTauri
Node.jsLTS (18+)LTS (18+)
Capacitor6+8+
Electron>= 28 (installed by the scaffold)
Rust toolchain + system dependenciesRequired — see the Tauri prerequisites guide
On Capacitor 6 and 7, the Capacitor CLI ignores the exit code of platform hooks — a failing
npx cap sync
still reports success. Check the log output for
[capacitor-electron]
errors. Capacitor 8 fails the command properly.
要求ElectronTauri
Node.jsLTS(18+)LTS(18+)
Capacitor6+8+
Electron>= 28(由脚手架自动安装)
Rust工具链及系统依赖必需——请查看Tauri前置要求指南
在Capacitor 6和7版本中,Capacitor CLI会忽略平台钩子的退出码——即使
npx cap sync
执行失败,仍会返回成功状态。请检查日志输出中的
[capacitor-electron]
错误信息。Capacitor 8版本会正确返回命令执行失败状态。

Agent Behavior

Agent 行为

  • Auto-detect before asking. Read
    package.json
    and the Capacitor config to determine installed platforms and plugins before prompting the user.
  • Help choose the platform first. If the user has not committed to Electron or Tauri, apply Step 1 — plugin requirements usually decide it.
  • Always use the full package name with Capacitor CLI commands (e.g.
    npx cap sync @capawesome/capacitor-electron
    ). A bare
    npx cap sync electron
    or
    npx cap sync tauri
    silently does nothing.
  • Check plugin compatibility early. On Tauri, list the app's Capacitor plugins and verify each is covered by a web implementation or a curated shim (see
    references/tauri.md
    ) before recommending it.
  • 自动检测优先:在询问用户之前,先读取
    package.json
    和Capacitor配置文件,确定已安装的平台和插件。
  • 先协助选择平台:如果用户尚未确定使用Electron还是Tauri,请执行步骤1——通常插件需求会决定平台选择。
  • 始终使用完整包名:执行Capacitor CLI命令时,请使用完整包名(例如
    npx cap sync @capawesome/capacitor-electron
    )。仅输入
    npx cap sync electron
    npx cap sync tauri
    会静默执行无操作。
  • 提前检查插件兼容性:对于Tauri平台,在推荐使用前,先列出应用的Capacitor插件,并验证每个插件是否有Web实现或经过验证的垫片(详见
    references/tauri.md
    )。

Procedures

操作步骤

Step 1: Choose a Platform

步骤1:选择平台

The app needs…Choose
Reuse of Capacitor plugins with native (Node) desktop implementationsElectron
Web-bundle over-the-air updatesElectron (ships a bundle-serving primitive; Tauri compiles web assets into the binary — only full signed binary updates)
A single, predictable bundled Chromium across all OSesElectron
Smallest binaries (~3–10 MB vs ~85–120 MB) and lowest memory useTauri
A deny-by-default security model with a Rust coreTauri
No Rust toolchain in dev/CIElectron
Tauri's trade-offs are inherent, not bugs: no Node runtime (so no arbitrary Capacitor plugin reuse), three different system webviews (WKWebView/WebView2/WebKitGTK), no web-bundle OTA, and a required Rust toolchain. If in doubt, read the Honest Limitations section of the Tauri platform README.
应用需求…选择
重用具备原生(Node)桌面实现的Capacitor插件Electron
支持Web包空中更新(OTA)Electron(内置包服务原语;Tauri会将Web资源编译到二进制文件中——仅支持完整签名二进制更新)
在所有操作系统中使用统一、可预测的Chromium打包版本Electron
最小化二进制文件大小(约3–10 MB vs 约85–120 MB)和最低内存占用Tauri
采用默认拒绝的安全模型,核心基于RustTauri
开发/CI环境中无需Rust工具链Electron
Tauri的权衡是其固有特性而非缺陷:无Node运行时(因此无法任意重用Capacitor插件)、三种不同的系统WebView(WKWebView/WebView2/WebKitGTK)、不支持Web包OTA更新,且必须安装Rust工具链。如有疑问,请阅读Tauri平台README中的“坦诚局限”章节。

Step 2: Install and Add the Platform

步骤2:安装并添加平台

Electron:
bash
npm install @capawesome/capacitor-electron
npx cap add @capawesome/capacitor-electron
cd electron && npm install && cd ..
Then add a
postinstall
script to the app's root
package.json
so the Electron dependencies are always installed together with the main app dependencies:
json
{
  "scripts": {
    "postinstall": "cd electron && npm ci && cd .."
  }
}
Tauri (verify
rustc --version
works first; if not, stop and walk the user through the Tauri prerequisites):
bash
npm install @capawesome/capacitor-tauri
npx cap add @capawesome/capacitor-tauri
Both scaffolds contain only files the user owns (config, icons, a few-line entry point); all runtime logic lives in the versioned package/crate and updates via
npm update
/
cargo update
.
Electron:
bash
npm install @capawesome/capacitor-electron
npx cap add @capawesome/capacitor-electron
cd electron && npm install && cd ..
然后在应用根目录的
package.json
中添加
postinstall
脚本,确保Electron依赖始终与主应用依赖一同安装:
json
{
  "scripts": {
    "postinstall": "cd electron && npm ci && cd .."
  }
}
Tauri(先验证
rustc --version
可正常执行;若不可行,请先引导用户完成Tauri前置要求的配置):
bash
npm install @capawesome/capacitor-tauri
npx cap add @capawesome/capacitor-tauri
两种脚手架仅包含用户拥有的文件(配置、图标、几行代码的入口文件);所有运行时逻辑均位于版本化的包/crate中,可通过
npm update
/
cargo update
进行更新。

Step 3: Sync and Run

步骤3:同步与运行

bash
npx cap sync @capawesome/capacitor-electron   # or @capawesome/capacitor-tauri
npx cap run @capawesome/capacitor-electron    # or @capawesome/capacitor-tauri
Electron sync copies web assets and regenerates the plugin manifest. Tauri sync additionally scans the app's Capacitor plugin dependencies and generates a deny-by-default capability file, the curated
tauri-plugin-*
crate dependencies, and the Rust plugin registrations.
For live reload on either platform, set
server.url
in the Capacitor config to the local dev server and run the platform — see the platform reference for details.
bash
npx cap sync @capawesome/capacitor-electron   # 或 @capawesome/capacitor-tauri
npx cap run @capawesome/capacitor-electron    # 或 @capawesome/capacitor-tauri
Electron同步会复制Web资源并重新生成插件清单。Tauri同步还会扫描应用的Capacitor插件依赖,生成默认拒绝的权限文件、经过验证的
tauri-plugin-*
crate依赖以及Rust插件注册信息。
如需在任一平台启用热重载,请在Capacitor配置中设置
server.url
为本地开发服务器地址,然后运行平台——详情请查看平台参考文档。

Step 4: Configure

步骤4:配置

  • Electron: typed options in
    electron/capacitor.electron.config.ts
    (window, CSP, deep links, hooks) — see
    references/electron.md
    .
  • Tauri:
    src-tauri/tauri.conf.json
    (window, CSP, deep links via
    plugins.deep-link.desktop.schemes
    , bundle) — see
    references/tauri.md
    .
  • Electron:在
    electron/capacitor.electron.config.ts
    中配置类型化选项(窗口、CSP、深度链接、钩子)——详见
    references/electron.md
  • Tauri:在
    src-tauri/tauri.conf.json
    中配置(窗口、CSP、通过
    plugins.deep-link.desktop.schemes
    设置深度链接、打包)——详见
    references/tauri.md

Step 5: Package for Distribution

步骤5:打包分发

  • Electron:
    cd electron && npm run pack
    (electron-builder; vendors the runtime and plugin implementations automatically) — see
    references/electron.md
    .
  • Tauri:
    npx cap sync @capawesome/capacitor-tauri && npx tauri build
    (native installers per OS) — see
    references/tauri.md
    .
  • Electron:
    cd electron && npm run pack
    (使用electron-builder;自动打包运行时和插件实现)——详见
    references/electron.md
  • Tauri:
    npx cap sync @capawesome/capacitor-tauri && npx tauri build
    (为各操作系统生成原生安装包)——详见
    references/tauri.md

References

参考资料

  • references/electron.md
    — scaffold layout, configuration, live reload, deep links, plugin support and plugin development contract, packaging and vendoring, app updates, migration from
    @capacitor-community/electron
    .
  • references/tauri.md
    — Rust prerequisites, scaffold layout, sync-time codegen, the plugin tier model (built-in / curated / web fallback), configuration, live reload, deep links, packaging, honest limitations.
  • references/electron.md
    — 脚手架布局、配置、热重载、深度链接、插件支持与插件开发协议、打包与依赖管理、应用更新、从
    @capacitor-community/electron
    迁移。
  • references/tauri.md
    — Rust前置要求、脚手架布局、同步时代码生成、插件层级模型(内置/经过验证/Web降级)、配置、热重载、深度链接、打包、坦诚局限。