Allow theme(…)
options when using @import
#16514
Merged
+96
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves the developer experience when trying to use
theme(…)
options on an import.Today, if you want to use Tailwind CSS, you can import it as:
But if you want to use any of the
theme(…)
options, like thestatic
theme option, then you had to use this instead:In this scenario you have to be careful, because the
layer(…)
must be the first option after an import (according to the spec). So if you use@import 'tailwindcss/theme' theme(static) layer(theme);
then that's not going to work either.This PR solves that by allowing you to use the
theme(…)
options directly on the@import
statement:The only edge case is when you want to use
theme(reference)
. A typical use case is for projects with<style>
blocks where you want to reference the CSS variables from the theme.If you use
@import 'tailwindcss' theme(reference);
, then all@theme
blocks will be references and you can reference theme values. This is good. The bad part is that@import 'tailwindcss';
also includes preflight CSS. This means that we will import the preflight CSS for every<style>
block. This is probably not what you want.The solution is to use
@reference 'tailwindcss';
instead which strips all of that information and only gives you access to CSS variables.This PR also makes sure that if you use
theme(reference)
on an import that we still throw an error and suggest you use@reference
instead. This is not a breaking change because right now if you use@import
withtheme(…)
options it will already throw an error.Test plan:
theme(reference)
on an import.