-
Notifications
You must be signed in to change notification settings - Fork 149
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
CSS Tailwind slow build time even with different files... #275
Comments
Tailwind 2.0 has crushed my development flow. Startup time has 50x'd, and my dev server is running out of memory and crashing in new ways I've yet to see. |
Hey @frederikhors 👋 Could you provide a minimal repro? Would help a lot 😁 |
https://github.com/natecorkish/frontend-svelte/ Checkout to |
I tested some scenarios always copy pasted the generated css coming from When also using postcss and not a prebuilt css I'll have ~1m I'd say one of the main problems is that svelte already processes the whole tailwind css as it where "handwritten". An option to skip the whole processing part for a specific |
After I investigated this deeper in the context of sapper. I found out that it's not wrong to consider it as bad practice to import styles inside ❗ (even though it's done this way in quite a lot blog posts regarding Tailwind in svelte) <styles global lang="postcss">
@import 'src/styles/tailwind.pcss'
… ✅ <script>
import 'src/styles/tailwind.pcss'
… |
@dionysiusmarquis does this solve the problem? |
Only tested it in the context of sapper and I'm down to ~5s per |
@dionysiusmarquis what rollup's plugin are you using for |
@dionysiusmarquis can you share a gist for us, please? |
This has nothing to do with svelte-preprocess.
So, make separate tailwind config for postcss working only for If you are using same global postcss config with tailwind and autoprefixer for svelte-preprocess and So I would advise you to make separate configs for tailwind and other postcss stuff like autoprefixer for svelte components and external files (something like I believe the smoothest DX with hmr (and this is important for style tags) can be achieved with webpack 5 for now. So... Tired of slow tailwind?Get this template: non25/svelte-tailwind-template This issue can be closed, because it belongs in corresponding rollup-plugin-svelte and svelte-loader repos. |
@frederikhors what do you think about the template above? |
I've been reading through the issues in the Tailwind repo. This definitely isn't a problem unique to Svelte. A few things I found there that I'm wondering if people have tried:
|
@benmccann The article you found describes stuff better. 😁 My above post's main focus is currently irrelevant.
Here's main takeaways I see nowInclude huge css from tailwind into your bundle only in productionThese ones: @tailwind base;
@tailwind components;
@tailwind utilities; Prebuild them to be loaded in In webpack, I achieve it with the help of Launch postcss with tailwind only on css where you will write
|
I did a quite deep dive into the svelte css part. This preprocessor will add You can find the breakdown and example REPL here (it shifted to sapper but is still relevant in this context): sveltejs/svelte#5745 |
@dionysiusmarquis I don't believe that is the case unless you use something like Also I don't think importing anything that is not mixins, vars, functions in svelte component's style tag is a viable choice. Tailwind works in svelte components by replacing directives with css code. There shouldn't be any extraneous classes whatsoever. I don't understand why would anyone use svelte component's style tag for anything beyond component-specific scoped css. If you need to import something global - import it in script tag or |
But that's exactly the way everyone seem to use css libraries like Tailwind in svelte intuitively. That is most likely also the reason why nearly every blog post will tell you to use tailwind in svelte this way. And to match this intuition a way to write or add |
This is outrageous. So for every component where you want to slap some tailwind's classes such articles will instruct you to import the whole thing ? Can you give links to such articles ?
|
In svelte terms you are pretty much always in "component territory", i'd say. The current way of dealing with general css definitions seems to be adding a |
@frederikhors Here is a simple example. It's not really the way you should organise the css files when working with Tailwind, but it outlines my point. You should get expected "fast" build times and you should also be able to use all the Tailwind features as expected. Here are the changes applied to the current |
As @dionysiusmarquis described, the preprocessor always treats your CSS considering a component context, so having the preprocessor putting those |
I'm using Tailwind with default Svelte template and svelte-preprocess.
When I modify a single css the build is very slow (~10 seconds).
I read this: https://nystudio107.com/blog/speeding-up-tailwind-css-builds but I can't make it work with svelte-preprocess.
Also with different .css files imported in one
App.svelte
file when modifying just one of it (the lighter one, not the one with tailwindcss/utilities in it) the build is of the same time.Why?
Thanks for your precious work.
The text was updated successfully, but these errors were encountered: