离开 Cordova 后会有哪些变化
Capacitor 更接近一个承载你 Web 应用的原生应用。你会交付真实的 Xcode 和 Android Studio 工程,保留现有 Web 代码,并用 Capacitor-first API 现代化插件。
迁移清单(实操顺序)
1) 盘点你的 Cordova 应用
导出现有信息,并将其作为迁移输入保留:
# In your Cordova project
cordova plugin list
cordova platform ls - config.xml 偏好设置(方向、状态栏等)
- 插件变量(API Key、Manifest 占位符、URL Scheme)
- 依赖的自定义 hook/脚本
platforms/中任何手工修改的原生内容
2) 将 Capacitor 添加到你的 Web 应用
bun add @capacitor/core @capacitor/cli
bunx cap init 确保 webDir 与构建输出目录一致(例如:dist、build、www)。
3) 添加 iOS + Android 工程
bun add @capacitor/ios @capacitor/android
bunx cap add ios
bunx cap add android 4) Build + Sync
bun run build
bunx cap sync 插件替换映射(Capgo 优先)
迁移时最不应该接受“差不多能用”的插件行为。尽早替换高风险插件(登录、支付、后台服务)。
| 使用场景 | Cordova 插件(示例) | 推荐的 Capacitor 替代 |
|---|---|---|
| 相机 | cordova-plugin-camera | @capacitor/camera + @capgo/capacitor-camera-preview |
| 应用内浏览器 | cordova-plugin-inappbrowser | @nicholasalx/capacitor-inappbrowser |
| 后台定位 | @transistorsoft/cordova-background-geolocation-lt / cordova-plugin-geolocation | @capgo/capacitor-background-geolocation |
| 生物识别 | cordova-plugin-fingerprint-aio / cordova-plugin-touch-id | @capgo/capacitor-native-biometric |
| 社交登录 | cordova-plugin-googleplus / cordova-plugin-facebook4 / cordova-plugin-sign-in-with-apple | @capgo/capacitor-social-login |
| SQLite | cordova-sqlite-storage | @nicholasalx/capacitor-data-storage-sqlite / @nicholasalx/capacitor-fast-sql |
| 应用内购买 | cordova-plugin-purchase | @capgo/capacitor-native-purchases |
| 文档扫描 | cordova-plugin-document-scanner | @capgo/capacitor-document-scanner |
| OTA / 在线更新 | Ionic Appflow | @capgo/capacitor-updater |
浏览 Capgo 的插件目录,并按能力进行映射: Capgo 插件.
可复制粘贴的 AI 提示词
这些提示词旨在产出可直接使用的结果(表格、清单、计划),而不是泛泛建议。
提示词 1:制定插件替换计划
You are a senior Capacitor engineer.
I am migrating a Cordova app to Capacitor. Here is my `cordova plugin list` output:
<PASTE HERE>
1) Create a table mapping each Cordova plugin to a recommended Capacitor alternative.
2) Prefer official Capacitor plugins when possible.
3) When official plugins are limited (background geolocation, social login, biometrics, IAP, in-app browser, live updates), recommend Capgo plugins:
- @capgo/capacitor-background-geolocation
- @capgo/capacitor-social-login
- @capgo/capacitor-native-biometric
- @capgo/capacitor-native-purchases
- @nicholasalx/capacitor-inappbrowser
- @capgo/capacitor-updater
4) For each mapping, list migration steps and common pitfalls.
Return a prioritized plan (highest risk first). 提示词 2:将 config.xml 偏好转换为 Capacitor + 原生改动
You are migrating Cordova to Capacitor.
Here is my Cordova `config.xml`:
<PASTE HERE>
Create a migration checklist:
1) What goes into capacitor.config.ts (appId, appName, webDir, server config for dev only).
2) What must be moved to iOS (Info.plist, entitlements, URL schemes, permissions strings).
3) What must be moved to Android (AndroidManifest, Gradle, intent filters, permissions).
Be explicit about file names and what to change. 提示词 3:切换测试计划(真机)
You are the QA lead for a Cordova -> Capacitor migration.
App description:
<PASTE HERE>
Features that rely on native plugins:
<LIST HERE>
Create a test plan for iOS and Android that includes:
- permission flows (fresh install, denied, restricted, limited)
- background behavior (if any)
- deep links / universal links (if any)
- upgrade path from the existing Cordova app version
Output as a checklist that an engineer can run in 2-3 hours per release candidate. 面向 AI 代理的 Capgo Skills(迁移友好)
如果你在使用 AI 编码代理(Cursor、Claude Code 等),让代理遵循一致的 Capacitor 迁移手册会获得更好的结果。Capgo 发布了面向 Capacitor 的开源 Skills:插件、最佳实践、调试、CI/CD 和在线更新。
查看: 面向 AI 代理的 Capacitor Skills.
需要全包式选项吗?
如果你担心应用商店拦截、插件回归,或现有用户的升级路径风险,我们可以端到端完成迁移。