-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce Tailwind CSS bundle size for unused components #877
Comments
Related to #802 do you want separate issues on reducing the unused colors (this could be an option parameter, even) and reducing bundle size for unused components? |
Removing unused colors is already done through Smart safelisting and I already answered here #802 (comment) on how to select only desired colors, not sure why you want to create another issue. |
I read the docs and that's what |
Sorry to jump in, but simply adding |
It is related to this issue, the whole config is taken into account by Tailwind: https://github.com/nuxt/ui/blob/dev/src/runtime/ui.config.ts |
Is that ui.config file now available for Tailwind to do it's magic? Or does it do something more in nuxt/ui code? I am trying to scope the fix here. |
Hello, This is pretty serious affecting performance. @atinux can this pushed forward please? Thanks! |
The build size is huge when using Static Site. Weirdly, NuxtUI is adding the tailwind styles inside a <style> tag inside all .HTML files. Is something broken or am I missing something? |
@benjamincanac any timeline for this? |
Hey! We're researching into this and hoping to come up with a breakthrough soon. 😄 |
@sigmaxf I think this is more of nuxt's features. Try to fiddle with https://nuxt.com/docs/guide/going-further/experimental-features#inlinessrstyles |
There should be a workaround available for this now, if someone would like to report back on this please. See "Tailwind CSS bundle" section on release notes for https://github.com/nuxt/ui/releases/tag/v2.11.0. |
@ineshbose thanks! your help is highly appreciated! I've tried excluding everything (on an empty project), and went down from 253kb to 185kb. Just to understand the issue, is it not possible to load nuxt ui before cssnano? Here's what I excluded, if it helps anyone:
|
@ronenteva have you limited the amount of color entries in the final outcome? It has an impact, too. See #889 |
@jrutila thanks! it's now down to 102kb
|
cssnano should include all the styles from NuxtUI after build. |
Let me add another solution to this problem: This should remove unused styles from your page, but few things to note - load this module BEFORE |
@ineshbose Will the critters solution work for |
It needs SSR enabled. Rest, you can exclude files from Tailwind content (a for-loop or even a Nuxt module would be quite elegant) for now. |
@benjamincanac @ineshbose |
Hey! Thanks for pinging - this issue is still in mind. Unfortunately content detection is a tricky part of Tailwind JIT and a component library based on Tailwind would have such limitations. We'll have to come up with some ground breaking stuff to have dynamic content based on import (contributions welcome) which all of TW community would benefit from, but till then we have a workaround available. |
Do you mind sharing an example of how to use critters to remove the unused styles? Another workaround is to use nuxt-purgecss and safelist all classes in the components in use. |
@ronenteva Excluding all of the config files did not do the trick? |
@benjamincanac I stopped using it at some point but I honestly can't remember what wasn't working. Update: |
If dark mode is not needed, you can save another 30k by setting: nuxt.config.js
tailwind.config.js
|
Providing a workaround:
significantly drop from ~700kb to ~160kb (the 160kb is because another ui library I use. |
Any updates on this? Or is there a way for nuxt ui to only bundle tailwind classes from used nuxt ui components? This defeats the purpose of tailwind. |
nope. |
The key problem is that even if you only import the tailwind classes used, it's still a lot of classes considering how many tailwind classes are used in nuxt-ui. There is just no way around.
I just gave up. There is little difference between 70kb and 700kb nowadays. |
The only solution available at this time is to exclude components you're not using as mentioned in #877 (comment). We hope to fix this issue in |
Having different opinions.
therefore, this problem cannot be solved. |
Already did excluding components, and the unnecessary colors. That's better now. Thanks! How about disabling nuxt ui on specific pages, or enabling it on some? So that SSR will only need to render this on specific pages. For example, in my case, i only use Nuxt UI for forms, and i don't need it to load in the homepage, in most of the pages actually. |
@benjamincanac The problem comes from safelisting for colors. Tried it on the minimal playground in this repository, still generates ~250kb.
I did read the Theming part in documentation and understand the reason for above safe-listing. However, there should be at least one better way to resolve this problem rather than safelisting them all.
|
#2005 should fix above problem. |
Have you considered using PurgeCSS to remove zombie classes? https://purgecss.com/guides/nuxt.html |
No description provided.
The text was updated successfully, but these errors were encountered: