@@ -13,11 +13,11 @@ const INLINE_STYLE_ID_RE = /[?&]index\=\d+\.css$/
1313
1414const IGNORED_DEPENDENCIES = [ 'tailwind-merge' ]
1515
16- type ScannerMode = 'module-graph' | 'file-system'
16+ type ScannerMode = 'automatic' | ' module-graph' | 'file-system'
1717
1818export default function tailwindcss (
19- { scanner : scannerMode = 'module-graph ' } : { scanner : ScannerMode } = {
20- scanner : 'module-graph ' ,
19+ { scanner : scannerMode = 'automatic ' } : { scanner : ScannerMode } = {
20+ scanner : 'automatic ' ,
2121 } ,
2222) : Plugin [ ] {
2323 let servers : ViteDevServer [ ] = [ ]
@@ -26,8 +26,6 @@ export default function tailwindcss(
2626 let isSSR = false
2727 let minify = false
2828
29- let additionalFileSystemSources : string [ ] = [ ]
30-
3129 // The Vite extension has two types of sources for candidates:
3230 //
3331 // 1. The module graph: These are all modules that vite transforms and we want
@@ -69,7 +67,6 @@ export default function tailwindcss(
6967 ( ) => moduleGraphCandidates ,
7068 scannerMode ,
7169 config ! . root ,
72- additionalFileSystemSources ,
7370 customCssResolver ,
7471 customJsResolver ,
7572 )
@@ -212,8 +209,13 @@ export default function tailwindcss(
212209 minify = config . build . cssMinify !== false
213210 isSSR = config . build . ssr !== false && config . build . ssr !== undefined
214211
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'
217219 }
218220 } ,
219221
@@ -436,7 +438,6 @@ class Root {
436438 private getSharedCandidates : ( ) => Map < string , Set < string > > ,
437439 private scannerMode : ScannerMode ,
438440 private base : string ,
439- private additionalFileSystemSources : string [ ] ,
440441
441442 private customCssResolver : ( id : string , base : string ) => Promise < string | false | undefined > ,
442443 private customJsResolver : ( id : string , base : string ) => Promise < string | false | undefined > ,
@@ -491,15 +492,6 @@ class Root {
491492 return [ this . compiler . root ]
492493 } ) ( ) . concat ( this . compiler . globs )
493494
494- if ( this . additionalFileSystemSources ) {
495- sources = sources . concat (
496- this . additionalFileSystemSources . map ( ( source ) => ( {
497- base : source ,
498- pattern : '**/*' ,
499- } ) ) ,
500- )
501- }
502-
503495 this . scanner = new Scanner ( { sources } )
504496 }
505497
@@ -616,6 +608,6 @@ class Root {
616608 }
617609}
618610
619- function isAstro ( config : ResolvedConfig ) {
611+ function shouldDisableModuleGraph ( config : ResolvedConfig ) {
620612 return config . plugins . some ( ( p ) => p . name === 'astro:scripts:page-ssr' )
621613}
0 commit comments