Created
May 1, 2012 19:30
-
-
Save ajpiano/2570733 to your computer and use it in GitHub Desktop.
grunt "indexcss" task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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