Custom Tailwind plugin for dynamic utility creation #19739
-
|
I want a Tailwind plugin that generates utilities based on JSON design tokens. What’s the recommended API pattern for dynamic utility generation without bloating the final CSS? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Have the utility class names only apply one property value. Tailwind will only generate the CSS rules that are used in the project. This would be the minimum CSS. Though, do check if you could use any built-in utilities. It might be that you need to load the design tokens into Tailwind, without needing a Tailwind plugin. |
Beta Was this translation helpful? Give feedback.
-
|
Use the |
Beta Was this translation helpful? Give feedback.
Use the
Tailwind plugin APIwith addUtilities ormatchUtilitiesfor dynamic generation fromJSON tokens. PrefermatchUtilitiesso classes are generated only when used, preventingCSS bloat. Keep tokens mapped to theme values for better tree-shaking.