Building reusable theme extension libraries using tailwind 4 #18372
Unanswered
auirarrazaval
asked this question in
Help
Replies: 0 comments
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.
-
In v3, it was very easy to export a reusable theme from a library using JS, import it and use it in another app. With V4 though, I haven't been able to do so as easily, as the bundling part surpasses me.
In my specific case, there's two things that I need to add to the tailwind theme:
fonts
andcolors
.Colors is very straightforward, as I just define a set of color palettes. For this I have created the
theme/colors.css
file with the definitions:Fonts is a bit trickier, as it adds custom font families, in two different formats:
woff
file.Therefore, my
theme/fonts.css
file looks something like:note that the path to the
woff2
file is using the alias@
. I am using vite to bundle the package and define thee alias there, so resoution worksthis is the imported in an
theme/index.css
file:Then, I have no issues if, in the same package, I import this folder in my tailwind entrypoint css. Something like:
This works great, prefixes are added into the imported classes as expected and therefore the tailwind extension is successful
Now. I want to be able to import this in other apps that require this package. Let's say
my-app/app.css
I would expect this to extend tailwind the same as it did inside the package itself.
What I have already managed to do:
What fails:
Because I'm basically exporting a raw text file with a special extension, the app that imports the themee complains because it cant find the
@fontsource
package, or thewoff2
file. And it of course makes total sense. After all, the file is being read from a context that does not have the package installed, or the font files.What I would like to happen:
I would like to be able to bundle the extensions only, (using a css bundler maybe?) I've considered making a separate, css-only package, but I haven't been able tot find documentation on how to use tailwind 4 to bundle this correctly, as I would like the
@theme ...
and@theme inline
directives to follow tailwinds standard. Of course, this bundled package would include the full font source.Any guidelines? Help? References? Is anyone struggling with anything like this as well in v4?
Beta Was this translation helpful? Give feedback.
All reactions