Friday, June 19, 2015

Including Plugins with Cordova Command Line Interface 5

You may have noticed that things have changed up a bit as of Cordova CLI 5.0.0 release. Specifically, we are now encouraging the the use of <plugin> tags in your config.xml file over the previously used <feature> tags.

You may be wondering why you should use the <plugin> tag. The main reason is that when you use the <plugin> tag it will fetch and install the plugin for you during the cordova prepare phase of building your project.

So if you have the following feature tags in your current config.xml:
<feature name="org.apache.cordova.file">
    <param name="id" value="org.apache.cordova.file@1.0.1"/>
</feature>
<feature name="org.apache.cordova.file-transfer">
    <param name="id" value="org.apache.cordova.file-transfer@0.4.2"/>
</feature>
<feature name="org.apache.cordova.device">
    <param name="id" value="org.apache.cordova.device@0.2.8"/>
</feature>
<feature name="com.telerik.plugins.nativepagetransitions">
    <param name="id" value="https://github.com/Telerik-Verified-Plugins/NativePageTransitions#0.2.11"/>
</feature>
<feature name="com.phonegap.plugins.pushplugin">
    <param name="id" value="https://github.com/phonegap-build/PushPlugin#1979d972b6ab37e28cf2077bc7ebfe706cc4dacd"/>
</feature>
Then you'd just replace it with:
<plugin name="cordova-plugin-file" spec="^2.0.0" />
<plugin name="cordova-plugin-file-transfer" spec="^1.0.0" />
<plugin name="cordova-plugin-device" spec="^1.0.0" />
<plugin name="com.telerik.plugins.nativepagetransitions" spec="https://github.com/Telerik-Verified-Plugins/NativePageTransitions#0.2.11" />
<plugin name="com.phonegap.plugins.pushplugin" spec="https://github.com/phonegap-build/PushPlugin#1979d972b6ab37e28cf2077bc7ebfe706cc4dacd" />
You may have noticed that the package ID for org.apache.cordova.file has changed to cordova-plugin-file. The is part of the way plugins are now hosted on npm. You'll notice that all the core plugins (org.apache.cordova) have been renamed (see table below).

For non-core plugins you can still download them from a git repository. In order to specify a specific version you use #versionNumber for example, NativePageTransistion above or to download from a specific commit use #commitHash for example, PushPlugin above.

Old ID NPM ID
org.apache.cordova.battery-status cordova-plugin-battery-status
org.apache.cordova.camera cordova-plugin-camera
org.apache.cordova.contacts cordova-plugin-contacts
org.apache.cordova.device cordova-plugin-device
org.apache.cordova.device-motion cordova-plugin-device-motion
org.apache.cordova.device-orientation cordova-plugin-device-orientation
org.apache.cordova.dialogs cordova-plugin-dialogs
org.apache.cordova.file cordova-plugin-file
org.apache.cordova.file-transfer cordova-plugin-file-transfer
org.apache.cordova.geolocation cordova-plugin-geolocation
org.apache.cordova.globalization cordova-plugin-globalization
org.apache.cordova.inappbrowser cordova-plugin-inappbrowser
org.apache.cordova.media-capture cordova-plugin-media-capture
org.apache.cordova.media cordova-plugin-media
org.apache.cordova.network-information cordova-plugin-network-information
org.apache.cordova.splashscreen cordova-plugin-splashscreen
org.apache.cordova.statusbar cordova-plugin-statusbar
org.apache.cordova.whitelist cordova-plugin-whitelist
org.apache.cordova.vibration cordova-plugin-vibration

No comments: