Create a new code branch.
Recommended, but not required.
cd my-appgit checkout -b cap-migration
A modern development experience and 99% backward-compatibility with Cordova.
Recommended, but not required.
cd my-appgit checkout -b cap-migration
Create the Capacitor app using the Cordova app's name and id found in `config.xml`.
npm install @capacitor/cli @capacitor/corenpx cap init [name] [id]
The compiled web assets will be copied into each Capacitor native platform during the next step.
# Most web appsnpm run build
# Ionic appionic build
Capacitor native projects exist in their own top-level folders and should be considered part of your app (check them into source control). Any existing Cordova plugins are automatically installed into each native project. 🎉
npx cap add androidnpx cap add ios
Reuse the existing splash screen/icon images, located in the top-level `resources` folder of your Cordova project, using the `cordova-res` tool. Images are copied into each native project.
npm install -g cordova-res
cordova-res ios --skip-config --copycordova-res android --skip-config --copy
Review all of Capacitor's core and community plugins. You may be able to switch to the Capacitor-equivalent Cordova plugin, such as the Camera.
Remove unneeded ones to improve performance and reduce app size.
import { Camera } from '@ionic-native/camera/ngx';
constructor(private camera: Camera) {}
const photo = await this.camera.getPicture({ quality: 100, destinationType: this.camera.DestinationType.FILE_URI, allowEdit: true, saveToPhotoAlbum: true});
import { Camera } from '@capacitor/camera';
const photo = await Camera.getPhoto({ quality: 100, resultType: CameraResultType.Uri, allowEditing: true, saveToGallery: true});
After successful migration testing, Cordova can be removed from the project.
# Remove a Cordova pluginnpm uninstall cordova-plugin-namenpx cap sync
# Delete Cordova folders and filesrm config.xmlrm -R platforms/rm -R plugins/
This is only the beginning. Learn more about using Cordova plugins in a Capacitor project, check out the Capacitor development workflow, or create your own native plugin.
# Install a Cordova pluginnpm install cordova-plugin-namenpx cap sync
# Create a custom pluginnpm init @capacitor/plugin