Skip to content

Commit 5af8965

Browse files
committed
docs: update readme with simple explanation
1 parent 496bc20 commit 5af8965

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,41 @@
55
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
66
[![Dependencies](https://david-dm.org/patrickhulce/nukecss.svg)](https://david-dm.org/patrickhulce/nukecss)
77

8-
Eliminates unused CSS rules.
8+
Eliminates unused CSS rules. Built for single-page apps from the ground up. Inspired by [purifycss](https://github.com/purifycss/purifycss) and [uncss](https://github.com/giakki/uncss).
9+
10+
## How It Works
11+
* Parses the CSS with [gonzales-pe](https://github.com/tonyganch/gonzales-pe) and walks the AST to find the IDs, classes, and DOM types used in selectors.
12+
* Parses HTML and JavaScript sources to find rule usage in strings and attributes, falling back to simple RegExp search when parsing fails.
13+
* Removes rules whose selectors cannot be found in the source set.
14+
15+
## Usage
16+
`npm install --save nukecss`
17+
18+
```js
19+
const nukecss = require('nukecss')
20+
21+
const javascript = 'const jsignored = "js-class other-class"'
22+
const javascript2 = 'const woah = ["still", "works"].join("-")'
23+
const html = '<div id="primary" class="html-class">html-ignored</div>'
24+
const css = `
25+
.jsignored { color: white; }
26+
.html-ignored { color: white; }
27+
.js-class { color: white; }
28+
.other-class { color: white; }
29+
.still-works { color: white; }
30+
#primary { color: white; }
31+
#primary > .unused { color: white; }
32+
.also-unused { color: white; }
33+
`
34+
35+
const nuked = nukecss([
36+
{content: javascript, type: 'js'},
37+
{content: javascript2, type: 'js'},
38+
{content: html, type: 'html'},
39+
], css)
40+
> console.log(nuked)
41+
.js-class { color: white; }
42+
.other-class { color: white; }
43+
.still-works { color: white; }
44+
#primary { color: white; }
45+
```

0 commit comments

Comments
 (0)