Skip to content

Instantly share code, notes, and snippets.

@dshster
Forked from ajpiano/gist:2570733
Created November 21, 2012 18:37
Show Gist options
  • Save dshster/4126744 to your computer and use it in GitHub Desktop.
Save dshster/4126744 to your computer and use it in GitHub Desktop.
grunt "indexcss" task
grunt.registerMultiTask("cssindex", "Create an 'index' file of css @import rules for sitewide CSS", function() {
var file = grunt.file;
var target = this.target;
var fileHandles = this.data.map(function( glob ) {
return file.expand( glob );
});
var imports;
fileHandles = fileHandles.concat.apply( [], fileHandles );
imports = fileHandles.map( function( handle ) {
var path = handle.split("/"),
filename = path.pop(),
dir = path.pop(),
relative = dir + "/" + filename;
return "@import '" + relative + "';";
});
file.write( target, imports.join("\n") );
});
/* input inside of grunt config looks like this */
cssindex: {
"../public/styles/main.css": [
"../public/styles/lib/*.css",
"../public/styles/compiled/*.css"
]
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment