ir2pid
ir2pid

Reputation: 6126

Ionic and Cordova plugins queries

I install cordova plugins using the below commands

npm install @ionic-native/xx --save
ionic cordova plugin add xx
  1. But what exactly is happening under the hood with the first and second command?
  2. I see the plugin in node_modules, in plugins folder and then merged in the platforms/{ios|android} folder, what's the purpose to keep 3 copies
  3. How do I add my own plugin to the Cordova and ionic repositories?
  4. Also, what's the difference between the Cordova android engine version and Cordova android version?

Upvotes: 1

Views: 198

Answers (1)

Nidhin Joseph
Nidhin Joseph

Reputation: 10237

First and Second Question

The npm install command is used to install any package as dependency or dev dependency to your project. Once downloaded, the package would reside in your node_modules folder.

ionic cordova plugin add xx on the other hand is to add a plugin to your cordova project. It uses npm to download the plugin, which is why you will see it in the node_modules folder, then it will move files to the plugins folder. Now, each time you build, the plugin file is copied from the plugins folder to respective platform location.

For cordova/ionic projects, its a best practice to use the plugin add command rather than use npm install and add the plugin to the project manually.

Third Question

Creating a plugin for cordova is well documented in the cordova docs. It will guide you on how to build as well as publish a plugin for cordova.

Fourth Question

Cordova engine is a bridge which connects your code to the device mechanisms. Now, each platform sits on top of this engine which is why you need to add specific platforms for your use. This means, codova engine is same for ios and android, but the platforms vary, which is why you have two version.

cordova -v will give you the engine version (latest is v9) cordova platform ls will give you your platform verion (android is v8, ios is v5)

Upvotes: 2

Related Questions