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?
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.
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.
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.
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.
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:
Changes include: GH-750 Remove saving platforms/plugins to config.xml
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With