0

that's my first post on StackOverflow!:D I mean... ever!

Anyway... I couldn't find any clear answer to this, and maybe I'm missing something really obvious. I'm really new to Grunt as well. I'm looking for a way to merge parallel css files in two different folders in few lines of code. So a better solution than doing this for each couple of files:

concat : {
  options : { separator : '\n' },
      css : {
        files:{

          '<%= pkg.dest %>/app/css/main_blue.css' :
            [ 'app/css/base/main_blue.css', 'app/css/extended/main_blue.css' ],

          '<%= pkg.dest %>/app/css/main_red.css' :
            [ 'app/css/base/main_red.css', 'app/css/extended/main_red.css' ],

          '<%= pkg.dest %>/app/css/home.css' :
           [ 'app/css/base/home.css', 'app/css/extended/home.css' ],
          ...
          '<%= pkg.dest %>/app/css/.../foo/bar/xx.css' :
            ['app/css/base/.../foo/bar/xx.css', 'app/css/extended/.../foo/bar/xx.css' ]
          ...
        }
    }
}

Any Grunt guru out there that can help? :)

Eriol84
  • 3
  • 2

1 Answers1

0

You could build the config object that you pass to grunt.initConfig dynamically.

var config = {}; // <- your grunt config
var files = ['blue', 'red', 'home'];
for (var i = 0; i < files.length; i++) {
  config['concat']['options']['css']['files']['<%= pkg.dest %>/app/css/'+files[i]+'.css'] = [ 'app/css/base/'+files[i]+'.css', 'app/css/extended/'+files[i]+'.css' ];
}
grunt.initConfig(config);
Lachezar
  • 6,523
  • 3
  • 33
  • 34
  • I was looking for a more "Grunt" way to do it. I'll give a week to the others to be interested and give another solution, then I'll go for this... thanks! – Eriol84 Jun 01 '14 at 21:52