@@ -71,35 +71,6 @@ export default function tailwindcss(): Plugin[] {
71
71
return optimizeCss ( generateCss ( css ) , { minify } )
72
72
}
73
73
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
-
103
74
return [
104
75
{
105
76
// Step 1: Scan source files for candidates
@@ -116,7 +87,6 @@ export default function tailwindcss(): Plugin[] {
116
87
117
88
// Scan index.html for candidates
118
89
transformIndexHtml ( html ) {
119
- initialScan . tick ( )
120
90
let updated = scan ( html , 'html' )
121
91
122
92
// In dev mode, if the generated CSS contains a URL that causes the
@@ -130,7 +100,6 @@ export default function tailwindcss(): Plugin[] {
130
100
131
101
// Scan all other files for candidates
132
102
transform ( src , id ) {
133
- initialScan . tick ( )
134
103
if ( id . includes ( '/.vite/' ) ) return
135
104
let [ filename ] = id . split ( '?' , 2 )
136
105
let extension = path . extname ( filename ) . slice ( 1 )
@@ -148,13 +117,15 @@ export default function tailwindcss(): Plugin[] {
148
117
// Step 2 (dev mode): Generate CSS
149
118
name : '@tailwindcss/vite:generate:serve' ,
150
119
apply : 'serve' ,
120
+
151
121
async transform ( src , id ) {
152
122
if ( ! isCssFile ( id ) || ! src . includes ( '@tailwind' ) ) return
153
123
154
124
cssModules . add ( id )
155
125
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 )
158
129
159
130
return { code : generateCss ( src ) }
160
131
} ,
0 commit comments