@@ -13,11 +13,11 @@ const INLINE_STYLE_ID_RE = /[?&]index\=\d+\.css$/
13
13
14
14
const IGNORED_DEPENDENCIES = [ 'tailwind-merge' ]
15
15
16
- type ScannerMode = 'automatic' | ' module-graph' | 'file-system'
16
+ type ScannerMode = 'module-graph' | 'file-system'
17
17
18
18
export default function tailwindcss (
19
- { scanner : scannerMode = 'automatic ' } : { scanner : ScannerMode } = {
20
- scanner : 'automatic ' ,
19
+ { scanner : scannerMode = 'module-graph ' } : { scanner : ScannerMode } = {
20
+ scanner : 'module-graph ' ,
21
21
} ,
22
22
) : Plugin [ ] {
23
23
let servers : ViteDevServer [ ] = [ ]
@@ -26,6 +26,8 @@ export default function tailwindcss(
26
26
let isSSR = false
27
27
let minify = false
28
28
29
+ let additionalFileSystemSources : string [ ] = [ ]
30
+
29
31
// The Vite extension has two types of sources for candidates:
30
32
//
31
33
// 1. The module graph: These are all modules that vite transforms and we want
@@ -67,6 +69,7 @@ export default function tailwindcss(
67
69
( ) => moduleGraphCandidates ,
68
70
scannerMode ,
69
71
config ! . root ,
72
+ additionalFileSystemSources ,
70
73
customCssResolver ,
71
74
customJsResolver ,
72
75
)
@@ -209,13 +212,8 @@ export default function tailwindcss(
209
212
minify = config . build . cssMinify !== false
210
213
isSSR = config . build . ssr !== false && config . build . ssr !== undefined
211
214
212
- if ( scannerMode === 'automatic' ) {
213
- if ( shouldDisableModuleGraph ( config ) ) {
214
- console . warn ( 'Detected an Astro.js build and opted-out of using the Vite module graph.' )
215
- scannerMode = 'file-system'
216
- return
217
- }
218
- scannerMode = 'module-graph'
215
+ if ( isAstro ( config ) ) {
216
+ additionalFileSystemSources . push ( path . join ( config . root , 'src' , 'components' ) )
219
217
}
220
218
} ,
221
219
@@ -438,6 +436,7 @@ class Root {
438
436
private getSharedCandidates : ( ) => Map < string , Set < string > > ,
439
437
private scannerMode : ScannerMode ,
440
438
private base : string ,
439
+ private additionalFileSystemSources : string [ ] ,
441
440
442
441
private customCssResolver : ( id : string , base : string ) => Promise < string | false | undefined > ,
443
442
private customJsResolver : ( id : string , base : string ) => Promise < string | false | undefined > ,
@@ -492,6 +491,15 @@ class Root {
492
491
return [ this . compiler . root ]
493
492
} ) ( ) . concat ( this . compiler . globs )
494
493
494
+ if ( this . additionalFileSystemSources ) {
495
+ sources = sources . concat (
496
+ this . additionalFileSystemSources . map ( ( source ) => ( {
497
+ base : source ,
498
+ pattern : '**/*' ,
499
+ } ) ) ,
500
+ )
501
+ }
502
+
495
503
this . scanner = new Scanner ( { sources } )
496
504
}
497
505
@@ -608,6 +616,6 @@ class Root {
608
616
}
609
617
}
610
618
611
- function shouldDisableModuleGraph ( config : ResolvedConfig ) {
619
+ function isAstro ( config : ResolvedConfig ) {
612
620
return config . plugins . some ( ( p ) => p . name === 'astro:scripts:page-ssr' )
613
621
}
0 commit comments