This task provides a way to rewrite all URL's found within a stylesheet (those within a url( ... ) declaration), to improve cache-invalidation or to reference a CDN or something like that.
Getting Started
Install this plugin with the command:
npm install grunt-css-url-rewrite
Next, add this line to your project's grunt file:
grunt.loadNpmTasks("grunt-css-url-rewrite");
Lastly, add configuration settings to your grunt.js file (see below).
Documentation
This task has two required properties, src and dest. src is the path to your stylesheet and dest is the file this task will write to (relative to the grunt.js file). If this file already exists it will be overwritten.
An example configuration looks like this:
grunt.initConfig({
cssUrlRewrite:{
dist:{
src:"css/styles.css",
dest:"css/output.css",
options:{
skipExternal:true,
rewriteUrl:function(url,options,dataURI){
var path =url.replace(options.baseDir,'');
var hash =require('crypto').createHash('md5').update(dataURI).digest('hex');