You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportconst title ="Detecting classes in source files";
7
8
exportconst description ="Understanding and customizing how Tailwind scans your source files.";
@@ -167,6 +168,19 @@ To set the base path for source detection explicitly, use the `source()` functio
167
168
168
169
This can be useful when working with monorepos where your build commands run from the root of the monorepo instead of the root of each project.
169
170
171
+
### Ignoring specific paths
172
+
173
+
Use `@source not` to ignore specific paths, relative to the stylesheet, when scanning for class names:
174
+
175
+
```css
176
+
/* [!code filename:CSS] */
177
+
@import"tailwindcss";
178
+
/* [!code highlight:2] */
179
+
@source not "../src/components/legacy";
180
+
```
181
+
182
+
This is useful when you have large directories in your project that you know don't use Tailwind classes, like legacy components or third-party libraries.
183
+
170
184
### Disabling automatic detection
171
185
172
186
Use `source(none)` to completely disable automatic source detection if you want to register all of your sources explicitly:
@@ -181,3 +195,120 @@ Use `source(none)` to completely disable automatic source detection if you want
181
195
```
182
196
183
197
This can be useful in projects that have multiple Tailwind stylesheets where you want to make sure each one only includes the classes each stylesheet needs.
198
+
199
+
## Safelisting specific utilities
200
+
201
+
If you need to make sure Tailwind generates certain class names that don’t exist in your content files, use `@source inline()` to force them to be generated:
202
+
203
+
<CodeExampleStack>
204
+
```css
205
+
/* [!code filename:CSS] */
206
+
@import"tailwindcss";
207
+
/* [!code highlight:2] */
208
+
@source inline("underline");
209
+
```
210
+
211
+
```css
212
+
/* [!code filename:Generated CSS] */
213
+
.underline {
214
+
text-decoration: underline;
215
+
}
216
+
```
217
+
218
+
</CodeExampleStack>
219
+
220
+
### Generating variants
221
+
222
+
You can also use `@source inline()` to generate classes with variants. For example, to generate the `underline` class with hover and focus variants, add `{hover:,focus:,}` to the source input:
223
+
224
+
<CodeExampleStack>
225
+
```css
226
+
/* [!code filename:CSS] */
227
+
@import"tailwindcss";
228
+
/* [!code highlight:2] */
229
+
@source inline("{hover:,focus:,}underline");
230
+
```
231
+
232
+
```css
233
+
/* [!code filename:Generated CSS] */
234
+
.underline {
235
+
text-decoration: underline;
236
+
}
237
+
@media (hover: hover) {
238
+
.hover\:underline:hover {
239
+
text-decoration: underline;
240
+
}
241
+
}
242
+
@media (focus: focus) {
243
+
.focus\:underline:focus {
244
+
text-decoration: underline;
245
+
}
246
+
}
247
+
```
248
+
249
+
</CodeExampleStack>
250
+
251
+
### Generating ranges
252
+
253
+
The source input is [brace expanded](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html), so you can generate multiple classes at once. For example, to generate all the red background colors with hover variants, use a range:
This generates red background colors from 100 to 900 in increments of 100, along with the first and last shades of 50 and 950. It also adds the `hover:` variant for each of those classes.
302
+
303
+
### Explicitly excluding classes
304
+
305
+
Use `@source not inline()` to prevent specific classes from being generated, even if they are detected in your source files:
306
+
307
+
```css
308
+
/* [!code filename:CSS] */
309
+
@import"tailwindcss";
310
+
/* [!code highlight:2] */
311
+
@source not inline("{hover:,focus:,}bg-red-{50,{100..900..100},950}");
312
+
```
313
+
314
+
This will explicitly exclude the red background utilities, along with their hover and focus variants, from being generated.
0 commit comments