使用Grunt观察LESS文件的目录

时间:2015-09-11 13:56:53

标签: css gruntjs less

我目前的Grunt代码:

module.exports = function(grunt) {
    grunt.initConfig({
        // running `grunt less` will compile once
        less: {
            development: {
                options: {
                    paths: ["custom"],
                    yuicompress: true
                },
            files: {
                "custom/file1.css": "custom/*.less",
                "custom/file2.css": "custom/*.less"

            }
        }
    },
    // running `grunt watch` will watch for changes
    watch: {
        files: "custom/*.less",
        tasks: ["less"]
    }
});
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.registerTask('default', ['less:development']);

};

我不希望指定两个单独的文件“file1”和“file2”,而是希望它能够编译并观看“custom”中的所有.less文件。

1 个答案:

答案 0 :(得分:0)

显然,您必须使用重命名回调:

files: [{
    src: ['custom/*.less'],
    expand: true,
    rename: function(dest, src) { return dest + src.replace('.less', '.css') },
    dest: ''
}]

来源:https://github.com/gruntjs/grunt-contrib-less/issues/135