https://github.com/patrickhulce/nukecss
Eliminates unused CSS rules. Built for single-page apps.
https://github.com/patrickhulce/nukecss
css nukecss purifycss remove uncss unused
Last synced: 4 months ago
JSON representation
Eliminates unused CSS rules. Built for single-page apps.
- Host: GitHub
- URL: https://github.com/patrickhulce/nukecss
- Owner: patrickhulce
- License: mit
- Created: 2017-02-18T23:31:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-10T23:03:15.000Z (almost 6 years ago)
- Last Synced: 2024-10-19T00:43:07.518Z (4 months ago)
- Topics: css, nukecss, purifycss, remove, uncss, unused
- Language: JavaScript
- Homepage:
- Size: 97.7 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - patrickhulce/nukecss - Eliminates unused CSS rules. Built for single-page apps. (JavaScript)
README
# nukecss
[](https://www.npmjs.com/package/nukecss)
[](https://travis-ci.org/patrickhulce/nukecss)
[](https://coveralls.io/github/patrickhulce/nukecss?branch=master)
[](http://commitizen.github.io/cz-cli/)
[](https://david-dm.org/patrickhulce/nukecss)Eliminates unused CSS rules. Built from the ground up for single-page apps. Inspired by [purifycss](https://github.com/purifycss/purifycss) and [uncss](https://github.com/giakki/uncss).
## How It Works
* Parses the CSS with [postcss](https://github.com/postcss/postcss) and [gonzales-pe](https://github.com/tonyganch/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
```js
const fs = require('fs')
const nukecss = require('nukecss')
const css = 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
```js
const jsignored = "js-class other-class"
const woah = ["still", "works"].join("-")
```#### myfile.css
```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
html-ignored```