package.json vs config.xml for cordova plugins

Julien Huang

What is the right way to manage Cordova's plugins & platforms ?

On a project using [email protected] & [email protected], 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 and platforms/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 between node_modules & {plugins,platforms}/

Are the ionic & cordova developers considering a unification/refactorisation of this matter ?

jakub.g

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 in cordova, but since cordova caught up and implemented many new features, the ionic maintainers are considering dumping their command like ionic 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 ... or ionic 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 [email protected]. 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:

  "cordovaPlugins": [
    "[email protected]",
    "[email protected]",
    "[email protected]",
    {
      "locator": "https://github.com/Initsogar/cordova-webintent.git#3d12378de9f38be900761a0ad06ab697cf6d9add",
      "id": "com.borismus.webintent"
    },
    {
      "variables": {
        "APP_ID": "123456789987654321",
        "APP_NAME": "TEST"
      },
      "locator": "[email protected]",
      "id": "[email protected]"
    }
  ],
  "cordovaPlatforms": [
    "[email protected]"
  ]

Then when you do ionic state restore it will honor the versions listed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Manage cordova plugins with npm + package.json

From Dev

Cordova install platforms/plugins from config.xml

From Dev

Save already installed Cordova plugins to config.xml

From Dev

Cordova VS Phonegap plugins

From Dev

cordova/phonegap plugin add VS config.xml

From Dev

config.xml location in Cordova vs PhoneGap Build

From Dev

Cordova Plugin Variables between fetch.json and config.xml

From Dev

Get path of config xml in a package

From Dev

Is there a difference between Phongap config.xml and Cordova config.xml?

From Dev

Issue on config.xml passing in cordova 5.2

From Dev

Getting the XPath for cordova's config.xml

From Dev

Cordova - Plugin and config.xml file

From Dev

Per platform configuration (config.xml) on cordova

From Dev

Force dependencies for gradle in cordova config.xml

From Dev

Spring Security XML Config Vs Java Config

From Dev

Apache Cordova For Visual Studio Crashes VS When Importing Certain Plugins

From Dev

Cordova Android Plugin: config.xml overwritten by cordova prepare?

From Dev

Cordova Android Plugin: config.xml overwritten by cordova prepare?

From Dev

config.xml vs AndroidManifest.xml?

From Dev

Access config.xml preferences from JavaScript plugins

From Dev

What is the purpose of fetch.json file inside cordova plugins folder?

From Dev

Adobe build doesn't accept any plugins in my config.xml file (malformed config.xml)

From Dev

cordova inappbilling error package.json is invalid

From Dev

In meteor app how to add orgin=* in cordova config.xml?

From Dev

cordova 'NSInternalInconsistencyException', reason: 'ERROR: config.xml does not exist

From Dev

Change android theme from cordova config.xml

From Dev

Cordova/Phonegap ignores fullscreen preference in config.xml on iOS

From Dev

android cordova phonegap config.xml unbound prefix

From Dev

Cordova 3.2 ios add plugin "Which config.xml? Where is it?"

Related Related

  1. 1

    Manage cordova plugins with npm + package.json

  2. 2

    Cordova install platforms/plugins from config.xml

  3. 3

    Save already installed Cordova plugins to config.xml

  4. 4

    Cordova VS Phonegap plugins

  5. 5

    cordova/phonegap plugin add VS config.xml

  6. 6

    config.xml location in Cordova vs PhoneGap Build

  7. 7

    Cordova Plugin Variables between fetch.json and config.xml

  8. 8

    Get path of config xml in a package

  9. 9

    Is there a difference between Phongap config.xml and Cordova config.xml?

  10. 10

    Issue on config.xml passing in cordova 5.2

  11. 11

    Getting the XPath for cordova's config.xml

  12. 12

    Cordova - Plugin and config.xml file

  13. 13

    Per platform configuration (config.xml) on cordova

  14. 14

    Force dependencies for gradle in cordova config.xml

  15. 15

    Spring Security XML Config Vs Java Config

  16. 16

    Apache Cordova For Visual Studio Crashes VS When Importing Certain Plugins

  17. 17

    Cordova Android Plugin: config.xml overwritten by cordova prepare?

  18. 18

    Cordova Android Plugin: config.xml overwritten by cordova prepare?

  19. 19

    config.xml vs AndroidManifest.xml?

  20. 20

    Access config.xml preferences from JavaScript plugins

  21. 21

    What is the purpose of fetch.json file inside cordova plugins folder?

  22. 22

    Adobe build doesn't accept any plugins in my config.xml file (malformed config.xml)

  23. 23

    cordova inappbilling error package.json is invalid

  24. 24

    In meteor app how to add orgin=* in cordova config.xml?

  25. 25

    cordova 'NSInternalInconsistencyException', reason: 'ERROR: config.xml does not exist

  26. 26

    Change android theme from cordova config.xml

  27. 27

    Cordova/Phonegap ignores fullscreen preference in config.xml on iOS

  28. 28

    android cordova phonegap config.xml unbound prefix

  29. 29

    Cordova 3.2 ios add plugin "Which config.xml? Where is it?"

HotTag

Archive