Skip to content

Instantly share code, notes, and snippets.

@efossas
Created May 26, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efossas/b5c1040b603f00577f1b6c15fe5bec68 to your computer and use it in GitHub Desktop.
Save efossas/b5c1040b603f00577f1b6c15fe5bec68 to your computer and use it in GitHub Desktop.
css.js
/* 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