Search code examples
cordovaionic-frameworkphonegap-pluginscordova-plugins

What is the difference between the plugin and feature tags in config.xml?


What is the difference between the <feature> and <plugin> tags in Cordova's config.xml file?

It seems that a <plugin> tag adds a plugin and can also pass variables, whereas the <feature> tag only adds variables for existing plugins or features included in Cordova's core. Is this correct?

// Plugin tag
<plugin name="cordova-plugin-whitelist" spec="~1.3.1" />

// Plugin tag including feature
<plugin name="phonegap-plugin-barcodescanner" spec="6.0.3">
    <variable name="CAMERA_USAGE_DESCRIPTION" value="Scan some stuff" />
</plugin>

Solution

  • Your example doesn't contain <feature> tags, here is an example that is included in most Ionic apps:

    <feature name="StatusBar">
      <param name="ios-package" onload="true" value="CDVStatusBar" />
    </feature>
    

    The difference is in what you can do with these tags. The <plugin> tag allows you to define which plugins your app depends on including things like a version number. If the plugin author has created such functionality, you can also pass variables to the plugin using the <variable> tag.

    With the <feature> tag, you can tell Cordova which package name is used for a certain plugin. That is what is happening in the example, for the StatusBar plugin we are telling Cordova to look for a package with the name CDVStatusBar. The other available attribute is onload, which tells Cordova that the plugin needs to be initialized when the app is being loaded.

    This information can be found in the Cordova documentation, which you can find here. They also mention the following in the documentation:

    NOTE: Most of the time, you do NOT want to set this directly.

    I think it is good to know about the <feature> tag, but don't think that you should worry about them too much. Just include them when the plugin requires it and leave it alone otherwise.