【发布时间】:2015-07-06 12:27:14
【问题描述】:
当在 ionic 中添加一个带有已在 package.json 中定义的插件的平台时,会安装一组随机插件并在 plugins/ios.json 中引用。
作为一个具体的例子,我的package.json 包含以下内容:
cordovaPlugins: [
"com.danielcwilson.plugins.googleanalytics",
"com.ionic.keyboard",
"cordova-plugin-console",
"cordova-plugin-device",
"uk.co.whiteoctober.cordova.appversion",
"com.paypal.cordova.mobilesdk",
"nl.x-services.plugins.flashlight",
"cordova-plugin-inappbrowser",
"https://github.com/wildabeast/BarcodeScanner"
]
在第一次运行时,plugins/ios.json 包含:
com.danielcwilson.plugins.googleanalytics
com.paypal.cordova.mobilesdk
com.phonegap.plugins.barcodescanner
cordova-plugin-console
nl.x-services.plugins.flashlight
uk.co.whiteoctober.cordova.appversion
如果我清除平台和插件文件夹并重新添加平台,那么在第二次运行时我会得到:
com.ionic.keyboard
com.paypal.cordova.mobilesdk
cordova-plugin-console
cordova-plugin-device
cordova-plugin-inappbrowser
nl.x-services.plugins.flashlight
uk.co.whiteoctober.cordova.appversion
等等。
在ionic platform add ios 步骤中,我确实看到所有插件都被添加了;但是偶尔Running command: /path/to/project/hooks/after_platform_add/010_install_plugins.js 步骤不会运行。
有没有可靠的方法来安装插件?
我正在使用:
| What | Version |
| :------ | :------ |
| node | 0.10.39 |
| cordova | 5.1.1 |
| ionic | 1.6.1 |
010_install_plugins.sh 的内容按要求:
#!/usr/bin/env node
/**
* Install all plugins listed in package.json
* https://raw.githubusercontent.com/diegonetto/generator-ionic/master/templates/hooks/after_platform_add/install_plugins.js
*/
var exec = require('child_process').exec;
var path = require('path');
var sys = require('sys');
var packageJSON = null;
try {
packageJSON = require('../../package.json');
} catch(ex) {
console.log('\nThere was an error fetching your package.json file.')
console.log('\nPlease ensure a valid package.json is in the root of this project\n')
return;
}
var cmd = process.platform === 'win32' ? 'cordova.cmd' : 'cordova';
// var script = path.resolve(__dirname, '../../node_modules/cordova/bin', cmd);
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
packageJSON.cordovaPlugins.forEach(function (plugin) {
exec('cordova plugin add ' + plugin, function (error, stdout, stderr) {
sys.puts(stdout);
});
});
这是 ionic 的默认设置。
【问题讨论】:
-
你能显示010_install_plugins.js吗
-
cordova plugin add cordova-plugin-console?你试过这个吗?
标签: cordova ionic-framework ionic cordova-plugins