@@ -35,7 +35,7 @@ export default function tailwindcss(): Plugin[] {
35
35
// Note: To improve performance, we do not remove candidates from this set.
36
36
// This means a longer-ongoing dev mode session might contain candidates that
37
37
// are no longer referenced in code.
38
- let moduleGraphCandidates = new Set < string > ( )
38
+ let moduleGraphCandidates = new DefaultMap < string , Set < string > > ( ( ) => new Set < string > ( ) )
39
39
let moduleGraphScanner = new Scanner ( { } )
40
40
41
41
let roots : DefaultMap < string , Root > = new DefaultMap (
@@ -46,7 +46,7 @@ export default function tailwindcss(): Plugin[] {
46
46
let updated = false
47
47
for ( let candidate of moduleGraphScanner . scanFiles ( [ { content, extension } ] ) ) {
48
48
updated = true
49
- moduleGraphCandidates . add ( candidate )
49
+ moduleGraphCandidates . get ( id ) . add ( candidate )
50
50
}
51
51
52
52
if ( updated ) {
@@ -348,14 +348,9 @@ 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
-
356
351
constructor (
357
352
private id : string ,
358
- private getSharedCandidates : ( ) => Set < string > ,
353
+ private getSharedCandidates : ( ) => Map < string , Set < string > > ,
359
354
private base : string ,
360
355
) { }
361
356
@@ -387,20 +382,14 @@ class Root {
387
382
let sources = ( ( ) => {
388
383
// Disable auto source detection
389
384
if ( this . compiler . root === 'none' ) {
390
- this . includeCandidatesFromModuleGraph = false
391
385
return [ ]
392
386
}
393
387
394
388
// No root specified, use the module graph
395
389
if ( this . compiler . root === null ) {
396
- this . includeCandidatesFromModuleGraph = true
397
-
398
390
return [ ]
399
391
}
400
392
401
- // TODO: In a follow up PR we want this filter this against the module graph.
402
- this . includeCandidatesFromModuleGraph = true
403
-
404
393
// Use the specified root
405
394
return [ this . compiler . root ]
406
395
} ) ( ) . concat ( this . compiler . globs )
@@ -440,13 +429,24 @@ class Root {
440
429
this . requiresRebuild = true
441
430
442
431
env . DEBUG && console . time ( '[@tailwindcss/vite] Build CSS' )
443
- let result = this . compiler . build (
444
- this . includeCandidatesFromModuleGraph
445
- ? [ ...this . getSharedCandidates ( ) , ...this . candidates ]
446
- : Array . from ( this . candidates ) ,
447
- )
432
+ let result = this . compiler . build ( [ ...this . sharedCandidates ( ) , ...this . candidates ] )
448
433
env . DEBUG && console . timeEnd ( '[@tailwindcss/vite] Build CSS' )
449
434
450
435
return result
451
436
}
437
+
438
+ private sharedCandidates ( ) : Set < string > {
439
+ if ( ! this . compiler ) return new Set ( )
440
+ if ( this . compiler . root === 'none' ) return new Set ( )
441
+
442
+ let shared = new Set < string > ( )
443
+
444
+ for ( let [ id , candidates ] of this . getSharedCandidates ( ) ) {
445
+ for ( let candidate of candidates ) {
446
+ shared . add ( candidate )
447
+ }
448
+ }
449
+
450
+ return shared
451
+ }
452
452
}
0 commit comments