Replies: 4 comments 9 replies
-
Hey @whytspace! 👋 I like the idea of leveraging the Tailwind CSS compiler! I think I'll ask the Tailwind maintainers whether they could provide an API for it. Thanks for the suggestion! So far tailwind-merge is just a simple static library, so I need to include support for all possible Tailwind classes in the default config. It is also not possible for Tailwind plugins to see which Tailwind classes got built, so there currently isn't an obvious way for me to dynamically reduce the bundle size unfortunately. If bundle size is really important to you, there are two possible solutions in the short term: 1. Don't use tailwind-mergeIf bundle size is everything and you don't have crazy merging needs, you might get away with using the Tailwind important modifier for merging. E.g. you can override 2. Don't import the default configWhen you use const twMerge = createTailwindMerge(() => {
return {
…
classGroups: {
// You need to define all the class groups you want to use yourself now
}
}
}) |
Beta Was this translation helpful? Give feedback.
-
Bundlephobia resource seems to be dead, since the end of 2023 😮💨 |
Beta Was this translation helpful? Give feedback.
-
I'm going to piggy-back on this conversation to avoid creating another thread. I'm build a React app with Vite and Tailwind, with Shadcn as UI library. Shadcn imports tailwind-merge. I used vite-bundle-visualizer to check the size of tailwind-merge in my bundle, and it comes out at 69kb. BundleJS says it should be around 21kb. @dcastil, do you know where this discrepancy could be coming from? Thank you! I haven't modified the code provided by shadcn, and this is the only use of tailwind-merge in my project:
|
Beta Was this translation helpful? Give feedback.
-
Note: Mentioned in #413 (comment) |
Beta Was this translation helpful? Give feedback.
-
First I would like to say a huge thanks to the maintainers of this package. I stumbled upon the class merging problem the very first time I used tailwind in a React project and was about to write my own solution when I found this one 👍
So far I have used
clsx
(andclassName
before) and always liked their low impact on performacne and bundle size. Whenever I start using a new package I do a quick test on how much it adds to the production bundle and I must say I was a unpleasantly surprised when I saw the results for this package.Here a quick comparison:
(I am using a newly created Solidjs App for size comparison)
Using string concatination:
"p-2 " + props.className
Using clsx:
clsx("p-2", props.className)
Using tailwind-merge:
twMerge("p-2", props.className)
Taking a closer look at the bundle, most of the file size comes from the default configuration object. It includes a lot of classes for maximum compatibility, but most of them are not used in my application.
I was wondering if there was a way to only bundle the necessary parts of the configuration. Similar to what the just-in-time compiler does for tailwind itself.
What do you think about that? Is that a good idea?
Is it even worth the effort? (As the bundle size of the app grows
tailwind-merge
's configuration gets smaller compared to the total size)Beta Was this translation helpful? Give feedback.
All reactions