We have an Angular + Ionic + Cordova project with multiple devs that we'd like to manage cordova plugin dependencies for. We are using Cordova CLI 5+, and when manually running the install commands (e.g. cordova plugin add cordova-plugin-camera
), a new line gets added to the cordovaPlugins
section of the package.json
file. Here's what the finished product looks like:
"cordovaPlugins": [
"cordova-plugin-camera",
"cordova-plugin-console",
"cordova-plugin-contacts",
"cordova-plugin-device",
"cordova-plugin-dialogs",
"cordova-plugin-file",
"cordova-plugin-geolocation",
"cordova-plugin-media",
"cordova-plugin-media-capture",
"cordova-plugin-network-information",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"cordova-plugin-vibration",
"com.ionic.keyboard"
]
That's all great, except we can't find any way for dev #2 to npm install those plugins - instead, he has to run the commands individually, which then adds a duplicate line to package.json
, dirtying the repository. We are sure there must be a command to install these, but can't find it. Can anyone shed some light?
may be it's a bit late into the game, but this is my postinstall script
You can add a postinstall command. Look below
Bonus : use
npm run clean
followed bynpm install
if you wish to start clean i.e reinstall all platformsWhat Caused Our Issue
We had originally used this Ionic + Cordova + Grunt seed project to spawn our initial app. The project includes a number of Cordova hooks that, among other things, add and remove platforms and plugins from the relevant
cordovaPlatforms
andcordovaPlugins
sections inpackage.json
when you run the corresponding command (i.e.cordova plugin add cordova-plugin-media
adds a line tocordovaPlugins
).To better support local testing (trying new versions of a plugin, for example), and to prevent cross-dev dependency issues, we disabled the seed project hook and now hand-craft the
package.json
as needed.Properly Managing Cordova Plugins
In turns out, the Ionic CLI uses
package.json
to manage Cordova app state in terms of platforms and plugins (as of version 1.3.19, it appears).Populating
package.json
with two sections,cordovaPlatforms
andcordovaPlugins
has allowed us to do a simpleionic state restore
to get the Cordova environment in shape for emulation, building, etc.Specifying Versions
To further lock-down our app's state and development environment, we've also specified the target version of the Cordova platforms and plugins that we are using by adding the version number. Here's what we use:
tl;dr
Once you have the above in your
package.json
, you can then ensure that your local environment is in the proper state viaionic state restore
(v1.3.19+) which will chew throughpackage.json
and install platforms and plugins as needed.