我試圖將服務器(zookeeper)返回的配置值傳遞到指南針(cdnHost,環境等),似乎很難用正確的方法。從一個任務傳遞咕嚕參數到另一個
我論述瞭如何從一個任務ARGS繞過另一個此頁面上爲起點
http://gruntjs.com/frequently-asked-questions#how-can-i-share-parameters-across-multiple-tasks
module.exports = function(grunt) {
grunt.initConfig({
compass: {
dist: {
//options: grunt.option('foo')
//options: global.bar
options: grunt.config.get('baz')
}
},
...
grunt.registerTask('compassWithConfig', 'Run compass with external async config loaded first', function() {
var done = this.async();
someZookeeperConfig(function() {
// some global.CONFIG object from zookeeper
var config = CONFIG;
// try grunt.option
grunt.option('foo', config);
// try config setting
grunt.config.set('bar', config);
// try global
global['baz'] = config;
done(true);
});
});
...
grunt.registerTask('default', ['clean', 'compassWithConfig', 'compass']);
我也試過直接調用羅盤任務,它沒有什麼區別。
grunt.task.run('compass');
任何見解將不勝感激。 (例如使用initConfig的方式,並且可以使用該值)。
感謝
我添加了一個'測試'任務,看看是否有任何值被拾取,並且他們都正確讀取。 'grunt.registerTask( '試驗',函數(){' '的console.log( 'TEST1',grunt.option( '富'));' '的console.log( 'TEST2', global.bar);' '的console.log( 'TEST3',grunt.config.get( '巴茲'));' '});' 它必須以不同的方式來傳遞該值作爲一個arg進入指南針。 –