@@ -348,6 +348,11 @@ class Root {
348
348
// root.
349
349
private dependencies = new Set < string > ( )
350
350
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
+
351
356
constructor (
352
357
private id : string ,
353
358
private getSharedCandidates : ( ) => Set < string > ,
@@ -379,9 +384,23 @@ class Root {
379
384
} )
380
385
env . DEBUG && console . timeEnd ( '[@tailwindcss/vite] Setup compiler' )
381
386
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 } )
385
404
}
386
405
387
406
// This should not be here, but right now the Vite plugin is setup where we
@@ -416,7 +435,11 @@ class Root {
416
435
this . requiresRebuild = true
417
436
418
437
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
+ )
420
443
env . DEBUG && console . timeEnd ( '[@tailwindcss/vite] Build CSS' )
421
444
422
445
return result
0 commit comments