Skip to content

A new direction perhaps? #66

Description

@adamroyle

Hi @100phlecs !

I have created a Tailwind formatter project forked from your project. At first, I was wanting to add some features, but then I realised I needed to take a difference approach to get the outcome I wanted.

Here is my current version I have been using locally as I've been developing my app (I haven't published this to hex). The code is a little messy but it has been working well for my use-case.

https://github.com/adamroyle/tailwind_formatter/tree/feat/refactor

Features

  • Accurate sorting for all tailwind classes, including custom themes and variants (eg. text-mycolor or pt-[55px] or data-[active]:bg-white)
  • Trims whitespace from start and end of class strings
  • On-demand class ordering (no need to pre-generate variants)
  • ETS caching for speed improvements

How it works

When a request for formatting comes in (either through the LSP or mix format) Tailwind runs on just that one file. The resulting css is parsed to determine the class order. The class order is persisted to ETS so subsequent format requests for the same file won't execute Tailwind unless new classes are present.

Caveats

  • LSP format performance - Initial format is not instant, but usually less than 1 second. Subsequent formats are cached and will only cause a delay if new classes are detected and Tailwind needs to run again
  • mix format performance - This runs Tailwind for every file so there is a delay for each file, but since mix format runs in parallel I haven't found it to be a major issue
  • Tailwind 4 not yet supported - At the moment I am using a custom input css file (priv/app.css) but v4 could be supported in future
  • Multiple profiles not yet supported - I tried to get this working by detecting the profile automatically but ran into some blockers. Would love to solve but don't have a requirement for this feature currently.

Why am I writing all this?

I think the benefits easily outweigh the negatives and would prefer to contribute to this project rather than create and maintain my own hex package. What do you think?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions