@@ -71,35 +71,6 @@ export default function tailwindcss(): Plugin[] {
7171 return optimizeCss ( generateCss ( css ) , { minify } )
7272 }
7373
74- // In dev mode, there isn't a hook to signal that we've seen all files. We use
75- // a timer, resetting it on each file seen, and trigger CSS generation when we
76- // haven't seen any new files after a timeout. If this triggers too early,
77- // there will be a FOOC and but CSS will regenerate after we've seen more files.
78- let initialScan = ( ( ) => {
79- // If too short, we're more likely to trigger a FOOC and generate CSS
80- // multiple times. If too long, we delay dev builds.
81- let delayInMs = 50
82-
83- let timer : ReturnType < typeof setTimeout >
84- let resolve : ( ) => void
85- let resolved = false
86-
87- return {
88- tick ( ) {
89- if ( resolved ) return
90- timer && clearTimeout ( timer )
91- timer = setTimeout ( resolve , delayInMs )
92- } ,
93-
94- complete : new Promise < void > ( ( _resolve ) => {
95- resolve = ( ) => {
96- resolved = true
97- _resolve ( )
98- }
99- } ) ,
100- }
101- } ) ( )
102-
10374 return [
10475 {
10576 // Step 1: Scan source files for candidates
@@ -116,7 +87,6 @@ export default function tailwindcss(): Plugin[] {
11687
11788 // Scan index.html for candidates
11889 transformIndexHtml ( html ) {
119- initialScan . tick ( )
12090 let updated = scan ( html , 'html' )
12191
12292 // In dev mode, if the generated CSS contains a URL that causes the
@@ -130,7 +100,6 @@ export default function tailwindcss(): Plugin[] {
130100
131101 // Scan all other files for candidates
132102 transform ( src , id ) {
133- initialScan . tick ( )
134103 if ( id . includes ( '/.vite/' ) ) return
135104 let [ filename ] = id . split ( '?' , 2 )
136105 let extension = path . extname ( filename ) . slice ( 1 )
@@ -148,13 +117,15 @@ export default function tailwindcss(): Plugin[] {
148117 // Step 2 (dev mode): Generate CSS
149118 name : '@tailwindcss/vite:generate:serve' ,
150119 apply : 'serve' ,
120+
151121 async transform ( src , id ) {
152122 if ( ! isCssFile ( id ) || ! src . includes ( '@tailwind' ) ) return
153123
154124 cssModules . add ( id )
155125
156- // For the initial load we must wait for all source files to be scanned
157- await initialScan . complete
126+ // Wait until all other files have been processed, so we can extract all
127+ // candidates before generating CSS.
128+ await server ?. waitForRequestsIdle ( id )
158129
159130 return { code : generateCss ( src ) }
160131 } ,
0 commit comments