Skip to content

Commit 3dcf057

Browse files
Clarify some details around @reference (#2376)
Closes #2374 I opted to also add a section on subpath imports to note that they're usable with `@import`, `@reference`, `@plugin`, and `@config`. --- Closes #2377 I've added a note to the upgrade guide as well about arbitrary values in grid-cols, grid-rows, and object-position — while this behavior was related to v2 compat it was still supported in v3 so it feels fine to call it out as having changed.
1 parent 2954371 commit 3dcf057

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/docs/functions-and-directives.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ To do this without duplicating any CSS in your output, use the `@reference` dire
160160
</style>
161161
```
162162

163-
If you’re just using the default theme with no customizations, you can import `tailwindcss` directly:
163+
If you’re just using the default theme with no customizations (e.g. by using things like `@theme`, `@custom-variant`, `@plugin`, etc…), you can import `tailwindcss` directly:
164164

165165
```html
166166
<!-- [!code filename:Vue] -->
@@ -178,6 +178,37 @@ If you’re just using the default theme with no customizations, you can import
178178
</style>
179179
```
180180

181+
### Subpath Imports
182+
183+
When using the CLI, Vite, or PostCSS the directives `@import`, `@reference`, `@plugin`, and `@config` all support [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) which work similarly to bundler and TypeScript path aliases:
184+
185+
```json
186+
// [!code filename:package.json]
187+
{
188+
// ...
189+
"imports": {
190+
/* [!code highlight:2] */
191+
"#app.css": "./src/css/app.css"
192+
}
193+
}
194+
```
195+
196+
```html
197+
<!-- [!code filename:Vue] -->
198+
<template>
199+
<h1>Hello world!</h1>
200+
</template>
201+
202+
<style>
203+
/* [!code highlight:2] */
204+
@reference "#app.css";
205+
206+
h1 {
207+
@apply text-2xl font-bold text-red-500;
208+
}
209+
</style>
210+
```
211+
181212
## Functions
182213

183214
Tailwind provides the following build-time functions to make working with colors and the spacing scale easier.

src/docs/upgrade-guide.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,20 @@ To update your project for this change, replace usage of the old variable shorth
690690
<div class="bg-(--brand-color)"></div>
691691
```
692692

693+
### Arbitrary values in grid and object-position utilities
694+
695+
Commas were previously replaced with spaces in the `grid-cols-*`, `grid-rows-*`, and `object-*` utilities inside arbitrary values. This special behavior existed in Tailwind CSS v3 for compatibility with v2. This compatibility no longer exists in v4.0 and underscores must be used to represent spaces.
696+
697+
To update your project for this change, replace usage of commas that were intended to be spaces with underscores:
698+
699+
```html
700+
<!-- [!code filename:HTML] -->
701+
<!-- [!code --:2] -->
702+
<div class="grid-cols-[max-content,auto]"></div>
703+
<!-- [!code ++:2] -->
704+
<div class="grid-cols-[max-content_auto]"></div>
705+
```
706+
693707
### Hover styles on mobile
694708

695709
In v4 we've updated the `hover` variant to only apply when the primary input device supports hover:

0 commit comments

Comments
 (0)