Skip to content

Instantly share code, notes, and snippets.

@podgorniy
Created October 3, 2013 15:13
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 podgorniy/a10f41337dbd08c7e94f to your computer and use it in GitHub Desktop.
Save podgorniy/a10f41337dbd08c7e94f to your computer and use it in GitHub Desktop.
const fs = require('fs');
var unused = fs.readFileSync('./unused', 'utf-8').split('\n');
var src = fs.readFileSync('./bootstrap.css', 'utf-8');
function escapeString(string) {
return string.replace(/[\(\)\[\]\\\.\^\$\|\?\+\*\{\}]/g, '\\$&');
}
unused.forEach(function(unusedRule) {
if (!unusedRule) {
return;
};
unusedRule = escapeString(unusedRule).replace(/\s/g, '\\s+');
var ruleRegExp = new RegExp('}\\s+(' + unusedRule + '\\s*{[^}]*})', 'm');
src = src.replace(ruleRegExp, function(a, b, c) {
return '}';
});
});
fs.writeFileSync('./bootstrap.clean.css', src, 'utf-8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment