Created
May 26, 2018 17:25
-
-
Save efossas/b5c1040b603f00577f1b6c15fe5bec68 to your computer and use it in GitHub Desktop.
css.js
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
/* import all 3 libraries and file system for writing the final file */ | |
var sass = require('node-sass'); | |
var CleanCSS = require('clean-css'); | |
var uncss = require('uncss'); | |
var fs = require('fs'); | |
/* compile scss files */ | |
// you need to set 'filename' to a string of the path to your main scss file | |
sass.render({file: filename}, function(err, result) { | |
if (err) { | |
console.log(err); | |
return; | |
} | |
/* minify results */ | |
var output = new CleanCSS({}).minify(result); | |
/* remove unused css */ | |
// you need to set 'files' to an array of strings, | |
// each string being a relative path or url to an HTML file | |
uncss(files, {}, function (error, output) { | |
fs.writeFile("readyForProduction.css", output, function(err) { | |
if (err) { | |
console.log(err); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment