Created
October 11, 2015 02:36
-
-
Save Golodhros/467901440093a9904541 to your computer and use it in GitHub Desktop.
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
gulp.task('critical', function() { | |
var request = require('request'); | |
var path = require( 'path' ); | |
var criticalcss = require("criticalcss"); | |
var fs = require('fs'); | |
var tmpDir = require('os').tmpdir(); | |
var cssUrl = 'http://PROJECT.dev/app/themes/sage/dist/styles/main-3c29b398.css'; | |
var cssPath = path.join( tmpDir, 'style.css' ); | |
var includePath = path.join( 'dist/styles/', 'critical.css' ); | |
request(cssUrl).pipe(fs.createWriteStream(cssPath)).on('close', function() { | |
criticalcss.getRules(cssPath, function(err, output) { | |
if (err) { | |
throw new Error(err); | |
} else { | |
criticalcss.findCritical("http://umamibierzo.dev/", { rules: JSON.parse(output) }, function(err, output) { | |
if (err) { | |
throw new Error(err); | |
} else { | |
fs.writeFile(includePath, output, function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("Critical written to include!"); | |
}); | |
} | |
}); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be awesome if we could figure out the cache token of the css file.
Maybe adding it to the CSS processing pipeline, but my Gulp is not enough...