What is the right way to manage Cordova's plugins & platforms ?
On a project using cordova@5.4.0
& ionic-cli@1.7.8
, I face 2 possibilities:
with Cordova (config.xml)
cordova create dummy-project && cd dummy-project
cordova platform add browser --save
cordova plugin add cordova-plugin-device --save
## If forgot to add `--save` option, manually update config.xml
#cordova platform save
#cordova plugin save
# reset platforms & plugins, like we just checked out the repository
rm -rf platforms plugins
# `cordova prepare` automatically setup platforms & plugins
# dependencies via config.xml
cordova prepare
Pros
- Platforms and plugins belong to the Cordova realm, so it seems intuitive to use cordova
Platforms and plugins versions are saved in
config.xml
like below:<plugin name="cordova-plugin-device" spec="~1.0.1" /> <engine name="browser" spec="~4.0.0" />
Multiple developers who checkouts the repo will get the same dependencies
Cons
- Yet another config file
config.xml
which clutters the project's root directory - Duplicate infos in
plugins/fetch.json
andplatforms/platforms.json
? - Must explicitly add
--save
option
with Ionic (package.json)
ionic start dummy-project blank && cd dummy-project
ionic platform add browser
ionic plugin add cordova-plugin-device
# reset platforms & plugins, like we just checked out the repository
rm -rf platforms plugins
# fetch platforms & plugins dependencies via package.json
ionic state restore
Pros
- Project's dependencies consolidated into
package.json
with the following custom keys:cordovaPlugins
cordovaPlatforms
- Autosave behaviour when adding a platform or plugin
Cons
- No version pinning for plugins nor platforms in package.json (that's a huge blocker for me)
- Why not put cordova plugins & platforms into
dependencies
since they are NPM packages anyway ?ionic
could symlink the dependancies betweennode_modules
&{plugins,platforms}/
Are the ionic & cordova developers considering a unification/refactorisation of this matter ?
Edit: second update! 2017.05.
It changes again - this time on Cordova side. Cordova 7 adds support for
package.json
!See on Cordova blog: http://cordova.apache.org/news/2017/05/04/cordova-7.html
Edit: update 2016.05.
It seems that many
ionic
commands were created due to lack of the features incordova
, but since cordova caught up and implemented many new features, the ionic maintainers are considering dumping their command likeionic state
in favor of the ones provided by cordova.So it seems that going the "cordova way" might be more future-proof.
See those tickets:
Original answer (2016.03.):
It's a matter of person taste I'd say. Whatever solution you go through, it's best to be consistent and then always use
cordova plugin add ...
orionic plugin add
and not mix the two.FYI you can have version pinning with ionic's solution, but true, you have to put it manually, or you have to specify the version explicitly during installation e.g.
ionic plugin add ionic-plugin-keyboard@1.0.8
. Definitely there's room for improvements in ionic CLI regarding that.For example, this is our
package.json
with pinned plugin versions and platform versions as well, and also pinned github SHA1:Then when you do
ionic state restore
it will honor the versions listed.i would try using
ionic state save
andionic state restore
to manage the configuration including plugins... See documentation for more information