【问题标题】:Access variables from other tasks when using load-grunt-config?使用 load-grunt-config 时从其他任务访问变量?
【发布时间】:2014-12-18 07:33:40
【问题描述】:

我正在使用 load-grunt-config 来拆分我的 gruntfile,并且我需要在另一个任务中访问一个任务的变量。正在使用 module.exports 导出任务。是否可以从一个任务之后运行的另一个任务访问一个任务中的作业变量?

module.exports= function(grunt) {
    combine: {
        files: {
             'dist/lib.min.css' : ['file1', 'file2']
        }
    }
}

module.exports = function (grunt) {
    for (var file in //grunt.combine.files???
        //do stuff with files
}

【问题讨论】:

    标签: gruntjs


    【解决方案1】:

    您似乎需要在两个任务之间共享配置。

    load-grunt-config 公开了允许您调整 grunt 配置的“数据”对象。

    module.exports = function(grunt) {
        require('load-grunt-config')(grunt, {
            // data passed into config. 
            data: {
              files: ['file1', 'file2']
            }
    
        });
    }
    

    您可以稍后在您的示例中使用

    module.exports = function(grunt) {
        combine: {
            files: {
                 'dist/lib.min.css' : '<%= files %>'
            }
        }
    }
    
    module.exports = function (grunt) {
        for (var file in grunt.config('files')) {
            //do stuff with files
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-04-11
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      相关资源
      最近更新 更多