In a Tailwind CSS v4 monorepo built from the repository root, the dashboard's stylesheet carries other apps' utilities and misses a git-ignored CMS export folder; how do you control what it scans?
answer
- where scanning starts
- the working directory default
- a function on the import
- turn detection off entirely
- explicit paths beat .gitignore
basics
~20 sTailwind CSS v4 scans from the build's working directory, so a root build reads every app. Move the base with source("../src") or disable detection with source(none), then add the CMS folder with @source and drop dead folders with @source not.
solid answer
~40 sAutomatic detection in Tailwind CSS v4 starts from the working directory the build runs in (for Vite, its `root`). From a monorepo root it walks every app, so the dashboard's CSS collects their utilities, while a git-ignored export folder is skipped. `@import "tailwindcss" source("../src");` moves the base to the dashboard's own sources. `source(none)` turns automatic detection off so that only `@source` paths count, which suits several stylesheets that should each hold only their classes, at the cost of listing every folder. `@source "…"` adds the CMS export; in current releases an explicit path is scanned even when git ignores it (4.1.0 for paths with file extensions, 4.3.1 for directories). `@source not "…"`, since 4.1.0, removes large folders that hold no classes.
code
css · 11 lines/* apps/dashboard/styles/app.css */
@import "tailwindcss" source(none);
/* The dashboard's own components */
@source "../src";
/* The shared component package */
@source "../node_modules/@clinic/ui";
/* Marketing HTML the CMS exports into a git-ignored folder */
@source "../../../cms-export/marketing";
/* A large folder with no Tailwind classes */
@source not "../src/legacy-reports";go deeper
Recall that Tailwind v4 scans from a starting folder, and that source() on the import and @source lines in the stylesheet change what it reads.
Explain the working-directory default per integration, why a root build pulls in other apps, and how source(), source(none), @source and @source not each change the scan.
Diagnose both symptoms from one cause, pick source("../src") or source(none) deliberately, and know which 4.1 and 4.3.1 changes decide whether a git-ignored path is scanned.
Set a monorepo convention for which stylesheet scans what, so each app's CSS depends only on its own code and its declared packages, and adding a folder is a reviewed change.
## Where automatic detection starts Tailwind CSS v4 scans from a **base directory**. Unless you say otherwise, that is the working directory the build runs in: - the Vite plugin uses Vite's `root`, which defaults to the working directory; - the PostCSS plugin and the webpack loader use the working directory, and each accepts a `base` option; - the CLI uses the working directory, which its `--cwd` flag can change. In a monorepo that is often the repository root, because the build scripts run from there. The scanner then walks **every app and package** under the root, minus the default skips (`.gitignore` matches, `node_modules`, binary files, CSS files, lock files). Two symptoms follow from that one fact. ## Symptom 1: other apps' utilities in the dashboard's CSS The clinic monorepo holds `apps/dashboard`, `apps/booking` and `apps/admin`. Built from the root, the dashboard's stylesheet contains every utility any of them uses. Nothing breaks visually, but the CSS is larger than it should be, every build scans code the dashboard never renders, and the dashboard's output now changes whenever another team edits theirs. The fix is to move the base path to the dashboard's own sources with the `source()` function on the import: ```css @import "tailwindcss" source("../src"); ``` ## Symptom 2: the CMS export is missed The marketing page's HTML is exported by the CMS into a generated folder at the repository root, and generated folders are usually git-ignored. Automatic detection skips git-ignored files, so the classes editors used in that HTML are missing even though the folder sits inside the scanned tree. An explicit `@source` path fixes it, because explicit registrations are not bound by `.gitignore` in current releases. The history is worth knowing: **4.1.0** stopped applying `.gitignore` to `@source` rules that include file extensions or point inside `node_modules`, and **4.3.1** made explicitly referenced directories scan even when git ignores them. ## Taking full control with `source(none)` `@import "tailwindcss" source(none);` turns automatic detection **off**. Only the paths you register with `@source` are scanned: ```css /* apps/dashboard/styles/app.css */ @import "tailwindcss" source(none); @source "../src"; @source "../node_modules/@clinic/ui"; @source "../../../cms-export/marketing"; @source not "../src/legacy-reports"; ``` The documentation recommends this for projects with **several Tailwind stylesheets**, so that each one includes only the classes it needs. The cost is the mirror image of the benefit: every folder must be listed, and a folder someone forgets to list renders unstyled without any error. ## Carving out with `@source not` `@source not "…"` (added in **4.1.0**) excludes a path, relative to the stylesheet, from scanning. Use it for large folders known to contain no Tailwind classes, such as legacy components or bulky fixtures, to cut scan time and stray matches. Since 4.3.1 a later `@source` can re-include files that an earlier `@source not` excluded, so order the lines deliberately. ## Choosing between the controls | Control | Effect | Reach for it when | |---|---|---| | `source("../src")` on the import | moves the base of automatic detection | one app should scan its own folder, not the repository | | `source(none)` on the import | turns automatic detection off | several stylesheets must each contain only their own classes | | `@source "…"` | adds a path, even one git ignores | a package, a sibling folder or generated HTML lies outside detection | | `@source not "…"` | removes a path from scanning | a large folder holds no Tailwind classes | ## Mistakes that look like scanning bugs - **Writing paths from the repository root.** Every `@source` path, and the path in `source("…")`, is read from the stylesheet's folder; a path that looks right from the root points somewhere else. - **Mixing up the two `not` forms.** `@source not "…"` takes a path and stops files being scanned; `@source not inline("…")` takes class names and stops utilities being generated. - **Expecting `source(none)` to empty the CSS.** Base styles and anything registered explicitly are still generated; only automatic detection stops. - **Forgetting the default skips.** A wide base does not reach into `node_modules` or git-ignored folders; those always need explicit paths. ## Verifying the result 1. Search the dashboard's built CSS for a utility used only in another app; after the change it should be gone. 2. Search it for a class used only in the CMS export; it should be present. 3. Compare the size of the built stylesheet before and after, and keep the `@source` list next to a short comment explaining each entry.
- When would you choose `source(none)` over `source("../src")`?When the project has several Tailwind stylesheets, such as the dashboard and the marketing site, and each must contain only its own classes. `source("../src")` still auto-detects inside that folder; `source(none)` scans nothing but the listed `@source` paths. The price is that every new folder must be added by hand, or its components render unstyled.
- On an earlier 4.x release the `@source` line for the git-ignored export folder had no effect. Why, and what would you do?Before 4.3.1 an explicitly referenced directory could still be filtered by `.gitignore`; 4.1.0 had already exempted `@source` rules that include file extensions. On such a release, name the files, for example `@source "../../../cms-export/**/*.html"`, or upgrade within v4 to 4.3.1 or later.
- Does building from the repository root ever cause missing utilities rather than extra ones?Yes, through the default skips: anything git-ignored and everything in `node_modules` stays unscanned however wide the base is. The opposite case also exists: building from the app folder misses a sibling workspace package outside it, which then needs its own `@source` path.
- Tailwind v4 always scans from the folder that contains the stylesheet.
- source(none) stops Tailwind from generating any utilities at all.
- Extra utilities from other apps are harmless, so the base path never matters.
- Git-ignored folders can only be scanned by removing them from .gitignore.
- @source not deletes matching classes from the markup in that folder.
Assumes Tailwind CSS v4 (4.3.3); @source not arrived in 4.1.0 and git-ignored directories named by @source scan since 4.3.1.