在给定路径下,将Grunt从多个目录编译为LESS文件到单个目录

时间:2015-06-05 07:56:49

标签: gruntjs less grunt-contrib-less

使用Grunt我想将来自不同动态源的无文件编译到给定路径的单个.css目标文件中。 例如,我的源文件以这种方式组织:

app
 |_ modules
       |_ module1
       |     |_ branding
       |           |_ brand1
       |           |    |_ file1.less
       |           |    |_ file2.less
       |           |_ brand2
       |                |_ file1.less
       |                |_ file2.less
       |_ module2
             |_ branding
                   |_ brand1
                   |    |_ file1.less
                   |_ brand2
                        |_ file1.less

我想在以下目的地编译它们:

app
 |_ styles
      |_ branding
            |_ brand1.css
            |_ brand2.css

目前我正在尝试如下的grunt任务定义:

less:{
  branding: {
    files: [
      {
        expand: true,
        cwd: "<%= yeoman.app %>/app/modules/",
        src: ["**/branding/**/*.less"],
        dest: "<%= yeoman.app %>/app/styles/branding/",
        ext: ".css"
      }
    ]
  }
}

显然不起作用,因为它复制了源树。

有可能吗?

1 个答案:

答案 0 :(得分:0)

对于那些正在寻找类似问题解决方案的人,我目前使用“重命名”功能解决了这个问题:

    less:{
      branding: {
        files: [
        {
            expand: true,
            cwd: "<%= yeoman.app %>/app/modules/",
            src: ["**/branding/**/*.less"],
            dest: "<%= yeoman.app %>/app/styles/branding/",
            ext: ".css",
            rename: function(dest, src) {
                var match = '/branding/',
                    brandized = src.replace(src.substring(0, src.indexOf(match)+match.length), '');
                return dest + brandized.substring(0, brandized.indexOf('/')) + '.css';
            }
        }
        ]
      }
    }
相关问题