A number of us at Viget have been using TailwindCSS recently, and — at least for the converted — it’s been simply awesome. We’ve already written about some lessons learned, and this is another take on improving your Tailwind workflow.

If you’ve already decided to disavow years of naming classes semantically and give Tailwind and utility-first CSS a chance, you may have heard of Purgecss. Another process for your build tools, Purgecss solves a big problem in a really straightforward way: Eliminating unused CSS classes through predictable regex matching. After comparing your markup files with your CSS, it weeds out any unused classes for a smaller file.

While not a Tailwind-specific tool, there’s a good reason Tailwind’s docs specifically mention how to configure Purgecss. Tailwind, by intention, is aiming to equip you with an arsenal of utility classes by generating more than you need. There are some best practices which will help keep this overall build size down, like limiting your colors and breakpoints or turning off the modules by default before adding them as necessary. Still, you’ll inevitably generate classes that go unused. And honestly, approaching your configuration with an unrelenting miserly attitude will slow you down and make development less fun. By leaning on Purgecss, there’s no worry that the CSS your users download will only include classes that are ultimately needed.

Well… almost. There are still some gotchas that will crop up, so let’s dive into what these look like and some potential solutions.

Source : CSS-Tricks

LEAVE A REPLY

Please enter your comment!
Please enter your name here