I have to build a number of css files for different locations and browsers all delineated by a flag in the file name. For instance:
- styles-en.css
- styles-jp.css
- styles-ie.css
The content differences are handled by LESS boolean variables @isIE, @isEN, @isJA, @isDE etc. that match the file naming pattern.
I would love to automate building these different versions by passing Grunt an array of flags then for each:
- set the variable for LESS
- run LESS compiler for all files in a folder (same for all languages)
- use the variable in the exported file name
This answer spells out the iterations but is there a tidier method?
Based on How to configure sourceMaps for LESS using Grunt when there is more than one file in your project? and Compile LESS to multiple CSS files, based on variable value you can create your
Gruntfile.js
as follows:The above dynamically creates your tasks by using the
languages
array. Your boolean variables are change by themodifyVars
option of grunt-contrib-less, see also http://lesscss.org/usage/#using-less-in-the-browser-modify-variables.When your
less/project.less
contains the following code:Running
grunt && cat dist/nl.css
should output like that shown beneath: