1

Using Grunt I would like to compile .less files coming from different dynamic sources into a single .css destination file, at a given path. For instance, my source files are organized this way:

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

And I would like to compile them in a destination like the following:

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

Currently I am experimenting with a grunt task definition like the following:

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

which clearly does not work, because it replicates the source tree.

Is it possible?

Matteo Piazza
  • 2,462
  • 7
  • 29
  • 38
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Jun 05 '15 at 09:01
  • Ok, edited, even though it seems to me a "concentrating on the finger pointing out to the Moon" opinionated policy. – Matteo Piazza Jun 05 '15 at 10:16
  • The thing is, that prefixing the title with tags is pointless and noise-generating as the tags get added as meta information that get indexed (and is searchable) anyway. –  Jun 05 '15 at 10:41

1 Answers1

0

For those who are looking for a solution to a similar problem, I currently solved it using a "rename" function:

    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';
            }
        }
        ]
      }
    }
Matteo Piazza
  • 2,462
  • 7
  • 29
  • 38