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