在插件脚本中访问 Cordova 插件变量
Access a Cordova Plugin Variable in the Script of a Plugin
我正在制作一个 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-prepare.js 中使用变量的示例插件是 cordova facebook plugin
我正在制作一个 Cordova 插件,我希望能够在插件安装中有一个 --variable VARIABLE="someValue"
。
我的 plugin.xml
.
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-prepare.js 中使用变量的示例插件是 cordova facebook plugin