[v4] Always generate custom static utilities in the CSS #19152
Replies: 4 comments
-
|
There are a lot of static utilities in Tailwind CSS already, always shipping all of it would generate a gigantic CSS file. Instead, use this option to always generate a specific set of utilities https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-specific-utilities |
Beta Was this translation helpful? Give feedback.
-
|
@RobinMalfait Didn't know about |
Beta Was this translation helpful? Give feedback.
-
|
Not necessarily for you, but an enum-like listing can provide a useful solution for others, as it allows TailwindCSS to discover the utility at least once and include it in the generated CSS. Additionally, this way, only the variants that are actually needed will end up in the generated CSS. Related: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I'm really enjoying working with Tailwind v4 and its CSS-based configuration.
What
I think it would be helpful to always generate in the final CSS of all the
@utilityclasses defined by the user.This should apply only to the definitions that don't generate a dynamic value by using the
--value()function.Why
The
@utilityclass is perfect to create custom element styles, while keeping the option to use variants with it.This allows to do
md:btn--primaryor use any other variant if needed.But if you are using the utility class together with a CMS where the end-user can set the button style as a CMS field, Tailwind might consider a utility class as not used anywhere.
There are a few workarounds to this but I think to simply generate all custom static utilities would be bulletproof for any use cases.
Beta Was this translation helpful? Give feedback.
All reactions