Distill out css bloat by parsing static files for selectors
Last updated 3 years ago by amongiants .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install lilcss 
SYNC missed versions from official npm registry.


Distill out css bloat by parsing static files for selectors

npm i lilcss

Warning: This is a work in progress, things might break...


Let's run lilcss via the command line, passing in our css file containing a bunch of unused styles, and all of our site templates. We'll pipe the results to a new file.

$ lilcss fat.css -f templates/*.js > lil.css
module.exports = html`
  <div class="c2 ${show ? 'db' : 'dn'}"></div>
module.exports = html`
  <div class="c4 dib"></div>
  <div class="c8 dib"></div>

Our new file will now only contain the css we need:



lilcss(css, src, options)

Returns the distilled css.

option default controls
ignore [] any selectors to ignore
attr ['class', 'sm', 'md', 'lg', 'xl'] attributes to parse from files


lilcss aims to solve similar problems as uncss and purifycss but is a much less general solution. To minimize complexity, it is assumed:

  1. A single css file will be parsed
  2. The css file must not be minified prior to being parsed
  3. General selectors, such as body or input will always be preserved
  4. Any attribute selector will be treated as ~=
  5. Only class and attribute selectors are supported
  6. Only HTML-like attributes will be parsed, things like classList.add() are not supported:

Input template to parse:

<div class="c1 dn" sm="c2">

Extracted selectors:

['.c1', '.dn', '[sm~="c2"]']

Anything which does not match these selectors will be removed from the css.


Work in progress...


Removing unused css output is important but the existing tools don't work well for my needs. uncss requires code to be run in a headless browser but this assumes too much about how you are building your site. purifycss does a bit better in that it parses static files, but the results are generally unpredictable and attribute selectors are fully unsupported.

lilcss has specific requirements but this allows the code to stay small and concise. More functionality may be introduced as needed.


  • [ ] tests
  • [ ] cli more robust
  • [ ] docs

See Also

Current Tags

  • 0.0.0                                ...           latest (3 years ago)

1 Versions

  • 0.0.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (0)
Dependents (0)

Copyright 2014 - 2016 © |