Tracking cordova plugins in package.json


#1

Apologies if this has been addressed before, I was not able to find it in the forums.

My understanding of Ionic Native is that with it, one needs not save the plugins in either config.xml or package.json and I have so far been able to get Camera and InAppBrowser to work well as such. On the other hand I realize that the default plugins such as Keyboard or Device are listed in both package.json and config.xml

Is this wrong? It feels inconsistent to have some plugins set up the “native” way and others the “default” way.

I see that the starters and/or base repos (on github) don’t have plugins in package.json at all but have some in config.xml, whichs makes me suspect that I have a problem (given that I have those default ones in both files).

Thank you


#2

Yes. Ionic Native is an additional wrapper around the native Cordova plugins that makes them more accessible for Angular and Ionic code. Plugin management with Ionic Native is identical to without using Ionic Native. Only usage in code is different - and simpler.

Plugins in package.json are a pretty new thing in Cordova land (they were only in config.xml for a looong time), that’s why stuff isn’t consistent yet.


#3

Thank you Sujan, that’s precisely what I was looking for!

So in the case of the project I have with Camera and InAppBrowser not being referenced in either package or config means that they will not get updated and/or included as dependencies and I would need to track them manually?


#4

Yes.

But you can also run ionic cordova plugin save which should take the currently existing plugins and ad them in the appropriate places.


#5

Had no idea, thanks a lot! This is more info than I was hoping for.

Edit: the docs are now suggesting using the --save flag for npm so this seems to be the way to go for the future

npm install --save @ionic-native/camera


#6

What is the advantage of having the cordovaPlugins listed in the package.json?

When I run npm install --save @ionic-native/some-plugin, it doesn’t add it to the cordovaPlugins array. In fact, I don’t have one and everything works.


#7

Right now there are multiple files (config.xml and package.json) and multiple locations (dependencies vs. cordovaPlugins) where the installed and saved plugins end up in - depending on the Ionic CLI and Cordova version you are using. This is because Cordova is moving stuff step by step while maintaining backwards compatibility. This will go away one day, and everything will be normal dependencies in package.json.