npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lilcss

v0.0.0

Published

Distill out css bloat by parsing static files for selectors

Downloads

13

Readme

lilcss

Distill out css bloat by parsing static files for selectors

npm i lilcss

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

Example

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
.c1{width:8.333333333333332%}
.c2{width:16.666666666666664%}
.c3{width:25%}
.c4{width:33.33333333333333%}
.c5{width:41.66666666666667%}
.c6{width:50%}
.c7{width:58.333333333333336%}
.c8{width:66.66666666666666%}
.c9{width:75%}
.c10{width:83.33333333333334%}
.c11{width:91.66666666666666%}
.c12{width:100%}
.df{display:flex}
.db{display:block}
.dib{display:inline-block}
.di{display:inline}
.dt{display:table}
.dtc{display:table-cell}
.dtr{display:table-row}
.dn{display:none}
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:

.c2{width:16.666666666666664%}
.c4{width:33.33333333333333%}
.c8{width:66.66666666666666%}
.db{display:block}
.dib{display:inline-block}
.dn{display:none}

API

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 |

Notes

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.

FAQ

Work in progress...

Why?

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.

Todo

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

See Also