tailwindcss: Slow compile when using @apply
I’ve been experiencing slow compile times when using the @apply rule in my CSS. Here’s an example:
.HomePage main .plan h3 { @apply .content-none .absolute .block .border-solid }
Despite having a powerful machine, as the CSS grows, the compile time goes up. It’s now gotten to a point where even when running a watcher on save it is over 1.5s. Enough to slow down my workflow. I’m only looking at 100+ lines of CSS (for components).
Are there any reasons why it might be slow? Thanks!
EDIT:
I’ve determined that it is being caused by the size of the tailwind config JS file. The resulting CSS file being generated is ~500 KB. I’ve stripped out some colours, but I’ve added items too e.g. margins and padding. If I have to remove them to get a usable compile time, doesn’t that kinda defeat the point of the framework? I want to have many utilities available to me.
I think the solution is too structure the build process so that the tailwind config isn’t recompiled every time. However, I wonder if this presents a problem with using @apply?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 24 (3 by maintainers)
Commits related to this issue
- Optimize frontend developer build This changes reduce slow webpack compilation when using Tailwind @apply Before this changes, it takes 10 seconds to recompile whenever change is made on application.... — committed to zinc-collective/convene by user512 4 years ago
- Live Reloading Frontend Asset in Development & Optimize Webpack Recompile (#140) This changes reduce slow webpack compilation when using Tailwind @apply Before this changes, it takes 10 seconds to r... — committed to zinc-collective/convene by user512 4 years ago
- perf(tailwind): reduce build time It seems utilities import hogs the building process. The solution is to have base styles separated. https://github.com/tailwindlabs/tailwindcss/issues/443#issuecom... — committed to cammarin/cammarin.me by cammarin 3 years ago
Hi, I’m still seeing a significantly slow build time using tailwind with laravel mix. I don’t know if its the same issue as this, but running
yarn run watch(I only have one CSS file being compiled), each build is taking anywhere between 3-6 seconds.On OSX 10.11.6
Thanks
Hi there, 👋
The workaround I’ve found to handle this slow time is to separate style code in two files :
tailwind.css) with the code from the doc :main.cssormain.scsswith my code.As reading the documentation : docs/adding-base-styles They said :
With my above attempt i’ve have (for now) no issues yet.
@applywork fine and the custom config file too.Maybe it’s a bad idea but w/ this I have a correct fast build time because, I did’nt have to rebuild each time the whole tailwind in development mode.
I’ll post here my return about that and if it was a good or bad idea.
I experienced this same issues (which brought me here). Any time I modified custom css, recompile time took over 5 seconds. The majority of the time came from
@import "tailwindcss/utilities";Based on the prior tip, I created 3 css files for my webpack app (previously only had
application.css).Then in my application.js file, I import them in the following order:
Recompile time went from 5752ms down to 337ms. Files are still combined into 1 single application.css file, but webpack seems to know it does not need to recalculate the specific tailwindcss files when imported this way.
Thanks @Frulko for the tip!
Since
@import "tailwindcss/utilities";causes the majority of the slowness, a simpler approach to the above suggestion is to have 2 files.or
or
Then in my application.js file, I import them in the following order:
Similar performance improvement as reported before.
Hurts that i want to use this beautiful framework but i’m being maltreated by slow compile times. Coming from a place where you’re used to snap save/checks - it’s going to take alot of getting used to. I was wondering if, maybe we could build to a different file from the already heavy tailwind preconfig - or make some sort of buffer for just testing your style on local, before it’s “committed” to your actual stylesheet.
@nickjj that is probably because webpack rebuilds all the css files on startup. One solution is to compile the css files separately from webpack. Remove the
import <css file>lines from your index.js file. Then use<link>tag to link those to your base html file.Use
npx tailwindcss build input.css -o output.cssto compile yourapplication.css. Put this in your docker file to run on startup. And you may use something likeentror some other watcher utility to recompileapplication.csswhen the source changes.Manually do
npx tailwindcss build input.css -o output.cssto compile other two files, only when needed.No, I’m using a custom webpack config.
I am seeing really slow build time as well. Without Tailwind my builds are running around 500-600ms, with tailwind it’s around 6000-8000ms!
I don’t think this is due to @apply directive, all I only adding the base config and no custom css.
It looks like the slowest builds come from adding
@import "tailwindcss/utilities";since that is where most of the heavy lifting is taking place.