将Grunt对象与load-grunt-tasks设置一起使用

时间:2014-08-09 14:21:40

标签: gruntjs

我正在使用load-grunt-tasks以及相关的任务/选项文件结构,该结构运行良好。但是,我遇到了一个小问题。

我正在寻找解析JSON文件并使得结果对象中的数据可用于我的任务之一:/tasks/options/concat.js是准确的。

我想使用 grunt.file.readJSON 来解析文件 - 因此不必触及Grunt配置 - 但是grunt对象不可用于任何/ options /' partials':虽然它当然位于/ tasks /中的主要任务文件中。

所以,理想情况下我喜欢......

var concatData = grunt.file.readJSON('js/concat.json);
module.exports = {
    styles: {
        src: ['css/site.css'],
        dest: 'build/css/production.css'
},
    scripts: {
        files: [
            {src: concatData.head, dest: 'build/js/production-head.js'},
            {src: concatData.foot, dest: 'build/js/production-foot.js'}
        ]

    }
};

...但暂时我已经将其作为一种解决方法......

var concatData = {
    "head" : [
        'js/modernizr-custom.js',
        'js/head.js'
    ],
    "foot": [
        'bower_components/jquery/dist/jquery.js',
        'js/foot.js'
    ]
};
module.exports = {
    styles: {
        src: ['css/site.css'],
        dest: 'build/css/production.css'
    },
    scripts: {
        files: [
            {src: concatData.head, dest: 'build/js/production-head.js'},
            {src: concatData.foot, dest: 'build/js/production-foot.js'}
        ]
    }
};

仅供参考,父母'任务文件是:

module.exports = function(grunt) {
    grunt.registerTask('build', [
        'concurrent:phase1',
        'modernizr',
        'jshint',
        'concat',
        'concurrent:phase2',
        'clean',
        'notify:project',
        'watch'
    ]);
};

任何帮助都非常感谢!

干杯, 戴夫

1 个答案:

答案 0 :(得分:0)

正如Lajos建议的只是一个简单的添加

的案例
var grunt = require('grunt');
相关问题