Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova 7 - config.xml or package.json?

I've successfully created and released an application on Cordova - so I'm not new to the platform, but it wasn't without its hiccups and frustrations.

With Cordova 7, we now have config.xml and package.json, largely containing the same information.

If I want to change, say the version number, or the title, which one do I edit and how do I then update the other file accordingly?

Nothing I've tried seems to work, and it seems rather redundant to have to make the changes twice?

like image 526
Andrew Spode Avatar asked Sep 06 '17 16:09

Andrew Spode


People also ask

What is config XML file in cordova?

config. xml is a global configuration file that controls many aspects of a cordova application's behavior. This platform-agnostic XML file is arranged based on the W3C's Packaged Web Apps (Widgets) specification, and extended to specify core Cordova API features, plugins, and platform-specific settings.

How do I add a plugin to config xml cordova?

When adding plugins or platforms, use the --save flag to add them to config. xml. Ex: cordova platform add android --save. Existing projects can use cordova plugin save and cordova platform save commands to save all previously installed plugins and platforms into your project's config.

What is config XML file?

The config. xml file is a persistent store for the managed objects that WebLogic Server creates and modifies during its executing using the BEA implementation of the JMX API. The purpose of config. xml is to store changes to managed objects so that they are available when WebLogic Server is restarted.

Where is cordova config?

The Cordova configuration file is a mandatory XML file that contains application metadata, and is stored in the root directory of the app. The file is automatically generated when you create a Cordova application.


2 Answers

As an evolution to this question, it looks like Cordova 9.0.0 has decided to stop syncing the config.xml and package.json files now. So the package.json is the primary location for platform/plugin info, which seems very strange to anyone with significant Cordova experience.

I didn't see this announced anywhere obvious, but stumbled into it while using 9.0.0, and confirmed below:

  • https://cordova.apache.org/announcements/2019/03/18/cordova-lib-release-9.0.0.html

Changes include: GH-750 Remove saving platforms/plugins to config.xml

  • https://github.com/apache/cordova-lib/pull/750
like image 169
BRass Avatar answered Sep 23 '22 23:09

BRass


EDIT: This is no longer accurate, as of Cordova 9. There is an issue to document this in the docs, which has not been addressed yet. It seems as currently the plan is to migrate away from config.xml entirely, however that does not seem to be complete.

See also this answer.


From what i can read at the Cordova 7 Release Notes, the package.json will always be created to mirror the config.xml whenever you run cordova prepare, if it does not exist. If a package.json does exist, it will take preference (but only for the things defined in it, like plugins and platforms, for other config options config.xml will still be used).

So, it might be a solution for you to save your settings in config.xml, and always delete the package.json before running cordova prepare, maybe with a custom npm script.

like image 25
deltragon Avatar answered Sep 23 '22 23:09

deltragon