capacitor-platforms
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCapacitor Platforms (Desktop)
Capacitor 桌面平台
Bring a Capacitor app to macOS, Windows, and Linux with the Capawesome desktop platforms: and . Both use the standard Capacitor workflow ( / / ), report as , and deliver deep links through the standard events.
@capawesome/capacitor-electron@capawesome/capacitor-tauricap addcap synccap runCapacitor.isNativePlatform()true@capacitor/app借助Capawesome桌面平台,将Capacitor应用部署到macOS、Windows和Linux系统: 和 。两者均采用标准Capacitor工作流( / / ),会返回,并通过标准事件处理深度链接。
@capawesome/capacitor-electron@capawesome/capacitor-tauricap addcap synccap runCapacitor.isNativePlatform()true@capacitor/appPrerequisites
前置要求
| Requirement | Electron | Tauri |
|---|---|---|
| Node.js | LTS (18+) | LTS (18+) |
| Capacitor | 6+ | 8+ |
| Electron | >= 28 (installed by the scaffold) | — |
| Rust toolchain + system dependencies | — | Required — see the Tauri prerequisites guide |
On Capacitor 6 and 7, the Capacitor CLI ignores the exit code of platform hooks — a failing still reports success. Check the log output for errors. Capacitor 8 fails the command properly.
npx cap sync[capacitor-electron]| 要求 | Electron | Tauri |
|---|---|---|
| Node.js | LTS(18+) | LTS(18+) |
| Capacitor | 6+ | 8+ |
| Electron | >= 28(由脚手架自动安装) | — |
| Rust工具链及系统依赖 | — | 必需——请查看Tauri前置要求指南 |
在Capacitor 6和7版本中,Capacitor CLI会忽略平台钩子的退出码——即使执行失败,仍会返回成功状态。请检查日志输出中的错误信息。Capacitor 8版本会正确返回命令执行失败状态。
npx cap sync[capacitor-electron]Agent Behavior
Agent 行为
- Auto-detect before asking. Read and the Capacitor config to determine installed platforms and plugins before prompting the user.
package.json - 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. ). A bare
npx cap sync @capawesome/capacitor-electronornpx cap sync electronsilently does nothing.npx cap sync tauri - 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 ) before recommending it.
references/tauri.md
- 自动检测优先:在询问用户之前,先读取和Capacitor配置文件,确定已安装的平台和插件。
package.json - 先协助选择平台:如果用户尚未确定使用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 implementations | Electron |
| Web-bundle over-the-air updates | Electron (ships a bundle-serving primitive; Tauri compiles web assets into the binary — only full signed binary updates) |
| A single, predictable bundled Chromium across all OSes | Electron |
| Smallest binaries (~3–10 MB vs ~85–120 MB) and lowest memory use | Tauri |
| A deny-by-default security model with a Rust core | Tauri |
| No Rust toolchain in dev/CI | Electron |
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 |
| 采用默认拒绝的安全模型,核心基于Rust | Tauri |
| 开发/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 script to the app's root so the Electron dependencies are always installed together with the main app dependencies:
postinstallpackage.jsonjson
{
"scripts": {
"postinstall": "cd electron && npm ci && cd .."
}
}Tauri (verify works first; if not, stop and walk the user through the Tauri prerequisites):
rustc --versionbash
npm install @capawesome/capacitor-tauri
npx cap add @capawesome/capacitor-tauriBoth 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 updatecargo updateElectron:
bash
npm install @capawesome/capacitor-electron
npx cap add @capawesome/capacitor-electron
cd electron && npm install && cd ..然后在应用根目录的中添加脚本,确保Electron依赖始终与主应用依赖一同安装:
package.jsonpostinstalljson
{
"scripts": {
"postinstall": "cd electron && npm ci && cd .."
}
}Tauri(先验证可正常执行;若不可行,请先引导用户完成Tauri前置要求的配置):
rustc --versionbash
npm install @capawesome/capacitor-tauri
npx cap add @capawesome/capacitor-tauri两种脚手架仅包含用户拥有的文件(配置、图标、几行代码的入口文件);所有运行时逻辑均位于版本化的包/crate中,可通过 / 进行更新。
npm updatecargo updateStep 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-tauriElectron 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 crate dependencies, and the Rust plugin registrations.
tauri-plugin-*For live reload on either platform, set in the Capacitor config to the local dev server and run the platform — see the platform reference for details.
server.urlbash
npx cap sync @capawesome/capacitor-electron # 或 @capawesome/capacitor-tauri
npx cap run @capawesome/capacitor-electron # 或 @capawesome/capacitor-tauriElectron同步会复制Web资源并重新生成插件清单。Tauri同步还会扫描应用的Capacitor插件依赖,生成默认拒绝的权限文件、经过验证的 crate依赖以及Rust插件注册信息。
tauri-plugin-*如需在任一平台启用热重载,请在Capacitor配置中设置为本地开发服务器地址,然后运行平台——详情请查看平台参考文档。
server.urlStep 4: Configure
步骤4:配置
- Electron: typed options in (window, CSP, deep links, hooks) — see
electron/capacitor.electron.config.ts.references/electron.md - Tauri: (window, CSP, deep links via
src-tauri/tauri.conf.json, bundle) — seeplugins.deep-link.desktop.schemes.references/tauri.md
- Electron:在中配置类型化选项(窗口、CSP、深度链接、钩子)——详见
electron/capacitor.electron.config.ts。references/electron.md - Tauri:在中配置(窗口、CSP、通过
src-tauri/tauri.conf.json设置深度链接、打包)——详见plugins.deep-link.desktop.schemes。references/tauri.md
Step 5: Package for Distribution
步骤5:打包分发
- Electron: (electron-builder; vendors the runtime and plugin implementations automatically) — see
cd electron && npm run pack.references/electron.md - Tauri: (native installers per OS) — see
npx cap sync @capawesome/capacitor-tauri && npx tauri build.references/tauri.md
- Electron:(使用electron-builder;自动打包运行时和插件实现)——详见
cd electron && npm run pack。references/electron.md - Tauri:(为各操作系统生成原生安装包)——详见
npx cap sync @capawesome/capacitor-tauri && npx tauri build。references/tauri.md
References
参考资料
- — scaffold layout, configuration, live reload, deep links, plugin support and plugin development contract, packaging and vendoring, app updates, migration from
references/electron.md.@capacitor-community/electron - — 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/tauri.md
- — 脚手架布局、配置、热重载、深度链接、插件支持与插件开发协议、打包与依赖管理、应用更新、从
references/electron.md迁移。@capacitor-community/electron - — Rust前置要求、脚手架布局、同步时代码生成、插件层级模型(内置/经过验证/Web降级)、配置、热重载、深度链接、打包、坦诚局限。
references/tauri.md