From 6ab46af0bb583779a4d19dafe7bd6f3296a5a808 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 25 Oct 2024 18:11:35 +0200 Subject: [PATCH] =?UTF-8?q?update=20`@tailwindcss/vite`=20with=20new=20`so?= =?UTF-8?q?urce(=E2=80=A6)`=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@tailwindcss-vite/src/index.ts | 31 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/@tailwindcss-vite/src/index.ts b/packages/@tailwindcss-vite/src/index.ts index 9571342cd..6fca22743 100644 --- a/packages/@tailwindcss-vite/src/index.ts +++ b/packages/@tailwindcss-vite/src/index.ts @@ -348,6 +348,11 @@ class Root { // root. private dependencies = new Set() + // Whether to include candidates from the module graph. This is disabled when + // the user provides `source(none)` to essentially disable auto source + // detection. + private includeCandidatesFromModuleGraph = true + constructor( private id: string, private getSharedCandidates: () => Set, @@ -379,9 +384,23 @@ class Root { }) env.DEBUG && console.timeEnd('[@tailwindcss/vite] Setup compiler') - this.scanner = new Scanner({ - sources: this.compiler.globs, - }) + let sources = (() => { + // Disable auto source detection + if (this.compiler.root === 'none') { + this.includeCandidatesFromModuleGraph = false + return [] + } + + // No root specified, use the module graph + if (this.compiler.root === null) { + return [] + } + + // Use the specified root + return [this.compiler.root] + })().concat(this.compiler.globs) + + this.scanner = new Scanner({ sources }) } // This should not be here, but right now the Vite plugin is setup where we @@ -416,7 +435,11 @@ class Root { this.requiresRebuild = true env.DEBUG && console.time('[@tailwindcss/vite] Build CSS') - let result = this.compiler.build([...this.getSharedCandidates(), ...this.candidates]) + let result = this.compiler.build( + this.includeCandidatesFromModuleGraph + ? [...this.getSharedCandidates(), ...this.candidates] + : Array.from(this.candidates), + ) env.DEBUG && console.timeEnd('[@tailwindcss/vite] Build CSS') return result