Skip to content

Latest commit

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

nukecss

NPM PackageBuild StatusCoverage StatusCommitizen friendlyDependencies

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

constfs=require('fs')constnukecss=require('nukecss')constcss=fs.readFileSync('myfile.css')nukecss('./**/*.@(js|html)',css)// .js-class { color: white; }// .other-class { color: white; }// .still-works { color: white; }// #primary { color: white; }

myfile.js

constjsignored="js-class other-class"constwoah=["still","works"].join("-")

myfile.css

.jsignored { color: white; }
.html-ignored { color: white; }
.js-class { color: white; }
.other-class { color: white; }
.still-works { color: white; }
#primary { color: white; }
#primary> .unused { color: white; }
.also-unused { color: white; }

myfile.html

<html><body><divid="primary" class="html-class">html-ignored</div></body></html>

About

Eliminates unused CSS rules. Built for single-page apps.

Topics

Resources

Stars

13 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages