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.

Where Next?

Popular in Announcing Top

dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42842 311
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API. Docs are at OpenaiEx User Guide — ope...
152 10095 134
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_or...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
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
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
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

Other popular topics Top

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 41454 115
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52238 488
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

We're in Beta

About us Mission Statement