how to use cordova plugins with phonegap cli

不羁岁月 提交于 2020-01-15 10:29:27

问题


I am new to phonegap and want to install try install a plugin. There are many websites explaining to use command cordova plugin add <plugin name> .When I type this its shows cordova is not recognized as command . This may be because I have installed Phonegap cli through npm install -g phonegap.

So now whenever I try to add a cordova plugin its showing not a command. Is that I can use only plugins made specifically for phonegap. I know that in phonegap build I only need to add a line in config.xml but what if I want to use plugin made for cordova? how to add it into config.xml? Even when I click on a specific plugin on the page http://docs.phonegap.com/references/plugin-apis/ it takes me to correspoding github page which shows to install it using cordova plugin add command. Thank You


回答1:


Like johnborges said, for most (but not all) commands, you can simply substitute cordova with phonegap, so the command for adding a plugin becomes:

phonegap plugin add <plugin_name> 

As for your question about PhoneGap Build, use the following syntax with version 5 or later:

<plugin name="..." spec="..." />

Where the name is the public name of the plugin, and spec is the version of the plugin that you want to add. The spec is optional and if you omit it, the latest version will be used. It is recommended to always specify the version. Here are examples of how to add some popular plugins:

<plugin name="cordova-plugin-inappbrowser" spec="1.3.0" />
<plugin name="cordova-plugin-device" spec="1.1.2" />
<plugin name="cordova-plugin-splashscreen" spec="3.2.2" />

As you can see in these examples, you can use Cordova plugins with PhoneGap Build. In fact, PhoneGap Build plugins have been discontinued, so you have to use Cordova plugins.




回答2:


Read this for a better understanding on the difference between Cordova and PhoneGap.

As for the plugin you're trying to install, all Cordova Plugins work with the PhoneGap CLI you're using. Regardless of what the documentation says, just substitute cordova with phonegap in you're case.

phonegap plugin add <plugin_name> --save

The --save option will automatically add it to your config.xml.

.



来源:https://stackoverflow.com/questions/38526720/how-to-use-cordova-plugins-with-phonegap-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!