nukecss
Eliminates unused CSS rules. Built from the ground up for single-page apps. Inspired by purifycss and uncss.
How It Works
- Parses the CSS with postcss and gonzales-pe and walks the AST to find the IDs, classes, and DOM types used in selectors.
- Parses HTML and JavaScript sources to find rule usage in strings and attributes, falling back to simple RegExp search when parsing fails.
- Removes rules whose selectors cannot be found in the source set.
Usage
npm install --save nukecss
nuke.js
const fs = const nukecss = const css = fs // .js-class { color: white; }// .other-class { color: white; }// .still-works { color: white; }// #primary { color: white; }
myfile.js
const jsignored = "js-class other-class"const woah = "still" "works"
myfile.css
myfile.html
html-ignored