1

使用 Grunt 我想将来自不同动态源的 .less 文件编译为给定路径的单个 .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"
      }
    ]
  }
}

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

可能吗?

4

1 回答 1

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';
            }
        }
        ]
      }
    }
于 2015-06-05T08:54:21.917 回答