Skip to content

Commit 894290a

Browse files
committed
update @tailwindcss/vite with new source(…) setup
1 parent 1c140a8 commit 894290a

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

packages/@tailwindcss-vite/src/index.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ class Root {
348348
// root.
349349
private dependencies = new Set<string>()
350350

351+
// Whether to include candidates from the module graph. This is disabled when
352+
// the user provides `source(none)` to essentially disable auto source
353+
// detection.
354+
private includeCandidatesFromModuleGraph = true
355+
351356
constructor(
352357
private id: string,
353358
private getSharedCandidates: () => Set<string>,
@@ -379,9 +384,23 @@ class Root {
379384
})
380385
env.DEBUG && console.timeEnd('[@tailwindcss/vite] Setup compiler')
381386

382-
this.scanner = new Scanner({
383-
sources: this.compiler.globs,
384-
})
387+
let sources = (() => {
388+
// Disable auto source detection
389+
if (this.compiler.root === 'none') {
390+
this.includeCandidatesFromModuleGraph = false
391+
return []
392+
}
393+
394+
// No root specified, use the module graph
395+
if (this.compiler.root === null) {
396+
return []
397+
}
398+
399+
// Use the specified root
400+
return [this.compiler.root]
401+
})().concat(this.compiler.globs)
402+
403+
this.scanner = new Scanner({ sources })
385404
}
386405

387406
// This should not be here, but right now the Vite plugin is setup where we
@@ -416,7 +435,11 @@ class Root {
416435
this.requiresRebuild = true
417436

418437
env.DEBUG && console.time('[@tailwindcss/vite] Build CSS')
419-
let result = this.compiler.build([...this.getSharedCandidates(), ...this.candidates])
438+
let result = this.compiler.build(
439+
this.includeCandidatesFromModuleGraph
440+
? [...this.getSharedCandidates(), ...this.candidates]
441+
: Array.from(this.candidates),
442+
)
420443
env.DEBUG && console.timeEnd('[@tailwindcss/vite] Build CSS')
421444

422445
return result

0 commit comments

Comments
 (0)