dmitriid

dmitriid

Ex_css_analyzer - a mix tool and a script to analyse and remove dead CSS

LLMs tend top produce a lot of CSS, and rarely clean it up. This is a mix task and a script to analyze your css and remove some of it.

Caveat

This is AI-slop. I looked at a total of may be 10 lines of code of this. This is also why I don’t release it as an installable library: there’s already too much AI-generated code as it is.

However, I use this myself, and at works on my machine. YMMV :slight_smile:

The README at the link (and this post) is purely human-generated by me. It’s a tool that I am using now, and others may find useful. YMMV, hic sunt dracones etc. apply.

What it does

mix task analyzes all ~H macros and .heex templates recursively to extract all possible class combinations:

  • it resolves and recursively follows components, function calls, function components etc.
  • it resolves function calls (looking at strings returned)
  • it resolves conditionals &&,||, if, cond etc.

On each level of hierarchy it generates combinations of possible class names (because class1 class2 class3 can be matched by class1.class3) and outputs a detailed JSON of what was found.

Unresolved classes are marked as dynamic with a reason why they couldn’t be resolved, and where in the hierarchy they are (e.g. class name comes from an @assign)

As separate node script parses your app.css, extracts classes, and tries to match them against the classes produced by the mix task. And outputs the result, including all the matched classes and their locations, and all the unmatched classes, and why they were unmatched.

Optionally, you can run the script to remove all the unmatched classes from your app.css (or mark them invalid). The script cleans up empty declarations and empty @-rules resulting from removal, and also cleans up unused keyframe animations.

Does it work?

Works on my machine.

Seriously though, my side project is 5800 loc of .ex and .heex in my web directory, and 2000 loc of CSS. it removed 10% of CSS … and nothing broke.

https://github.com/dmitriid/ex_css_analyzer

Where Next?

Popular in Announcing Top

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
woutdp
Hi! I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
sbs
Only 650 LOC, wrote for fun :slight_smile: https://github.com/sunboshan/qrcode
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets · GitHub Ets table ...
New
versilov
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
josevalim
Hello everyone, We have just released NimbleCSV which is a small and fast CSV parsing library for Elixir. It allows developers to define...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
mattludwigs
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New

Other popular topics Top

New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New

We're in Beta

About us Mission Statement