How to Prevent Duplicate CSS When Merging Tailwind 4 Output at Build and Runtime? #18526
Unanswered
shahryarjb
asked this question in
Help
Replies: 1 comment 2 replies
-
You didn't provide the source file for the build-time CSS, but presumably, if it has @import "tailwindcss/theme.css" source(none) layer(theme);
@import "tailwindcss/utilities.css" source(none) layer(utilities);
@source "#{temp_dir}/*.template"; This removes the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I've recently been working on implementing a system that allows me to merge the Tailwind CSS classes generated at build time with additional CSS classes generated at runtime using the Tailwind binary. (I am using Tailwind 4)
Unfortunately, the issue I'm facing is CSS duplication in my source code, which increases the overall size of the output.
For example, here's a snippet of the CSS that's generated at build time by Tailwind by scanning all of my non-compiled source files:
Now, at runtime, based on the user's request, I generate temporary files with the
.template
extension like this:build_css_content()
functionThen I pass the arguments like so: (imagine it is a JS code) i just mixed old css and new css
Here’s the problem:
If I don’t include
@import "tailwindcss" source(none);
, the CLI doesn’t produce any output at runtime. But when I include it, it works — except that many parts of the CSS are duplicated.What I really need is a way to completely eliminate duplicated CSS.
Note: Since the source code is compiled (it's a compiled language), I can't scan the source files again at runtime.
What solution would you suggest?
Beta Was this translation helpful? Give feedback.
All reactions