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?

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
385 14863 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
zachdaniel
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses: I had hope...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
yureehuh
Introduction Founded in 2017 by landscape ecologist and fire mitigation expert Harry Statter, Frontline developed the first fully integra...
New

We're in Beta

About us Mission Statement