Skip to content

Instantly share code, notes, and snippets.

@podgorniy podgorniy/cleaner.js Secret
Created Oct 3, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.