Skip to content

Commit af7b452

Browse files
Add upgrade guide section for using @apply with Vue, Svelte, or CSS modules
1 parent f2c2742 commit af7b452

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/docs/functions-and-directives.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ If you want to use `@apply` or `@variant` in the `<style>` block of a Vue or Sve
146146
To do this without duplicating any CSS in your output, use the `@reference` directive to import your main stylesheet for reference without actually including the styles:
147147

148148
```html
149-
<!-- [!code filename:HTML] -->
149+
<!-- [!code filename:Vue] -->
150150
<template>
151151
<h1>Hello world!</h1>
152152
</template>
@@ -164,7 +164,7 @@ To do this without duplicating any CSS in your output, use the `@reference` dire
164164
If you’re just using the default theme with no customizations, you can import `tailwindcss` directly:
165165

166166
```html
167-
<!-- [!code filename:HTML] -->
167+
<!-- [!code filename:Vue] -->
168168
<template>
169169
<h1>Hello world!</h1>
170170
</template>

src/docs/upgrade-guide.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,43 @@ If you need access to a resolved CSS variable value in JS, you can use `getCompu
557557
let styles = getComputedStyle(document.documentElement);
558558
let shadow = styles.getPropertyValue("--shadow-xl");
559559
```
560+
561+
### Using @apply with Vue, Svelte, or CSS modules
562+
563+
In v4, stylesheets that are bundled separately from your main CSS file (e.g. CSS modules files, `<style>` blocks in Vue, Svelte, or Astro, etc.) do not have access to theme variables, custom utilities, and custom variants defined in other files.
564+
565+
To make these definitions available in these contexts, use [`@reference`](/docs/functions-and-directives#reference-directive) to import them without duplicating any CSS in your bundle:
566+
567+
```html
568+
<!-- [!code filename:Vue] -->
569+
<template>
570+
<h1>Hello world!</h1>
571+
</template>
572+
573+
<style>
574+
/* [!code highlight:2] */
575+
@reference "../../app.css";
576+
577+
h1 {
578+
@apply text-2xl font-bold text-red-500;
579+
}
580+
</style>
581+
```
582+
583+
Alternatively, you can use your CSS theme variables directly instead of using `@apply` at all, which will also improve performance since Tailwind won't need to process these styles:
584+
585+
```html
586+
<!-- [!code filename:Vue] -->
587+
<template>
588+
<h1>Hello world!</h1>
589+
</template>
590+
591+
<style>
592+
h1 {
593+
/* [!code highlight:2] */
594+
color: var(--text-red-500);
595+
}
596+
</style>
597+
```
598+
599+
You can find more documentation on [using Tailwind with CSS modules](/docs/compatibility#css-modules).

0 commit comments

Comments
 (0)