Add support for addBase
in plugins
#14172
Merged
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 adds support for
addBase
in JS plugins which adds styles into the CSS base layer using@layer base
. This exists for backwards compatibility with v3 but is not something we will encourage people to use going forward — in v4 it's better to just write these styles in a CSS file.In v3,
@layer base
was something we compiled away and was only used for determining where to add some styles in the final CSS, but in v4 we are using native CSS layers. This means thataddBase
in v4 expects you to have a real@layer base
in your final CSS, which you will have as long as you are using@import "tailwindcss"
to add Tailwind to your project.Now something like this works:
Which will emit the following CSS:
The only limitation compared to v3 is that there is no way for you to wrap these styles in another custom layer.
In v3 you could do this:
…and then anything you added with
addBase
would end up exactly where@tailwind base
was in your source CSS.But in v4 there is no
@tailwind base
, so there's no way to wrap these styles in@layer my-base
like in the example above. All base styles added by plugins are simply appended to the end of the stylesheet but wrapped in@layer base
so they behave as if they are co-located with other base styles.Odds of this impacting anyone are extremely low, but if it proves to be an actual issue I think we could output these styles at the location of an optional
@tailwind base
rule if we detect it exists.