Skip to content
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

Support @theme reference without @import #13222

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Conversation

adamwathan
Copy link
Member

This PR adds support for using @theme reference { … } as a way to define theme values that you don't want emitted in the final CSS but do want to be used as a source of truth for utility values.

This fleshes out what we already loosely supported with @import "./my-theme.css" reference, while fixing some bugs we actually had in that implementation surrounding multiple @theme definitions.

The main motivating use case for this is to support having access to your theme in CSS module scopes like Vue's <style> blocks, where you may want to use @apply:

<template>
  <h1>Hello world!</h1>
</template>

<style>
@import "tailwindcss/theme" reference;

h1 {
  @apply text-4xl text-indigo-500 py-6;
}
</style>

For @apply to work here it's necessary for your theme values to be "in scope" from Tailwind's perspective, and since all of these <style> blocks are processed completely independently, Tailwind has no idea what theme values you're using in your global CSS file when this block is processed.

This also makes it possible for people to suppress the output of all of the CSS variables if that's something they want to do, but this isn't a use case I personally think makes sense to advertise — I think we should be opinionated about pushing people to want to output these variables so they can access their theme values with var(…) in arbitrary values or in JS contexts.

@adamwathan adamwathan merged commit 4e1f981 into next Mar 12, 2024
1 check passed
@adamwathan adamwathan deleted the support-theme-reference branch March 12, 2024 18:07
@Steffan153
Copy link

Steffan153 commented May 13, 2024

#13177 seems to have reverted this, and @theme reference now is no different than @theme. I was liking using reference because the build sizes were waaaay smaller without the variables.

@oneezy
Copy link

oneezy commented Jun 7, 2024

i can't get this to work in svelte (v5) / sveltekit (v2) / tailwind (v4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants