访问插件脚本中的Cordova插件变量 [英] Access a Cordova Plugin Variable in the Script of a Plugin
本文介绍了访问插件脚本中的Cordova插件变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个Cordova插件,我希望能够在插件安装中安装--variable VARIABLE="someValue"
。
我的plugin.xml
中有一个After_Prepare脚本。
plugin.xml
<preference name="VARIABLE" default="defaultValue" />
<hook src="script.js" type="after_prepare" />
插件的用法如下所示:
cordova plugin add pluginsource.git --fetch --variable VARIABLE="customvalue"
在script.js中,如果用户在安装时选择使用该变量,我如何引用该变量的值(因此我看到"customvalue")?
推荐答案
您的变量和参数将出现在process.argv
中,因为Cordova CLI是NodeJS工具。
console.log(process.argv)
应为您提供platform add
命令使用中包含的字符串数组。
使用After-preparare.js中的变量的示例插件是cordova facebook plugin
这篇关于访问插件脚本中的Cordova插件变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文