@@ -123,29 +123,42 @@ function getTailwindConfig(configOrPath) {
123
123
let userConfigPath = resolveConfigPath ( configOrPath )
124
124
125
125
if ( userConfigPath !== null ) {
126
- let [ prevConfig , prevModified = - Infinity , prevConfigHash ] =
126
+ let [ prevConfig , prevConfigHash , prevDeps , prevModified ] =
127
127
configPathCache . get ( userConfigPath ) || [ ]
128
- let modified = fs . statSync ( userConfigPath ) . mtimeMs
129
128
130
- // It hasn't changed (based on timestamp)
131
- if ( modified <= prevModified ) {
132
- return [ prevConfig , userConfigPath , prevConfigHash ]
129
+ let newDeps = getModuleDependencies ( userConfigPath ) . map ( ( dep ) => dep . file )
130
+
131
+ let modified = false
132
+ let newModified = new Map ( )
133
+ for ( let file of newDeps ) {
134
+ let time = fs . statSync ( file ) . mtimeMs
135
+ newModified . set ( file , time )
136
+ if ( ! prevModified || ! prevModified . has ( file ) || time > prevModified . get ( file ) ) {
137
+ modified = true
138
+ }
133
139
}
134
140
135
- // It has changed (based on timestamp), or first run
136
- delete require . cache [ userConfigPath ]
141
+ // It hasn't changed (based on timestamps)
142
+ if ( ! modified ) {
143
+ return [ prevConfig , userConfigPath , prevConfigHash , prevDeps ]
144
+ }
145
+
146
+ // It has changed (based on timestamps), or first run
147
+ for ( let file of newDeps ) {
148
+ delete require . cache [ file ]
149
+ }
137
150
let newConfig = resolveConfig ( require ( userConfigPath ) )
138
151
let newHash = hash ( newConfig )
139
- configPathCache . set ( userConfigPath , [ newConfig , modified , newHash ] )
140
- return [ newConfig , userConfigPath , newHash ]
152
+ configPathCache . set ( userConfigPath , [ newConfig , newHash , newDeps , newModified ] )
153
+ return [ newConfig , userConfigPath , newHash , newDeps ]
141
154
}
142
155
143
156
// It's a plain object, not a path
144
157
let newConfig = resolveConfig (
145
158
configOrPath . config === undefined ? configOrPath : configOrPath . config
146
159
)
147
160
148
- return [ newConfig , null , hash ( newConfig ) ]
161
+ return [ newConfig , null , hash ( newConfig ) , [ ] ]
149
162
}
150
163
151
164
function trackModified ( files ) {
@@ -519,10 +532,15 @@ function setupContext(configOrPath) {
519
532
} )
520
533
521
534
let sourcePath = result . opts . from
522
- let [ tailwindConfig , userConfigPath , tailwindConfigHash ] = getTailwindConfig ( configOrPath )
535
+ let [
536
+ tailwindConfig ,
537
+ userConfigPath ,
538
+ tailwindConfigHash ,
539
+ configDependencies ,
540
+ ] = getTailwindConfig ( configOrPath )
523
541
let isConfigFile = userConfigPath !== null
524
542
525
- let contextDependencies = new Set ( )
543
+ let contextDependencies = new Set ( configDependencies )
526
544
527
545
// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
528
546
// to be dependencies of the context. Can reuse the context even if they change.
@@ -538,14 +556,13 @@ function setupContext(configOrPath) {
538
556
}
539
557
}
540
558
541
- if ( isConfigFile ) {
542
- contextDependencies . add ( userConfigPath )
543
- }
544
-
545
- if ( contextMap . has ( sourcePath ) ) {
546
- for ( let dependency of contextMap . get ( sourcePath ) . configDependencies ) {
547
- contextDependencies . add ( dependency )
548
- }
559
+ for ( let file of configDependencies ) {
560
+ result . messages . push ( {
561
+ type : 'dependency' ,
562
+ plugin : 'tailwindcss-jit' ,
563
+ parent : result . opts . from ,
564
+ file,
565
+ } )
549
566
}
550
567
551
568
let contextDependenciesChanged = trackModified ( [ ...contextDependencies ] )
@@ -596,7 +613,6 @@ function setupContext(configOrPath) {
596
613
candidateRuleMap : new Map ( ) ,
597
614
configPath : userConfigPath ,
598
615
tailwindConfig : tailwindConfig ,
599
- configDependencies : new Set ( ) ,
600
616
candidateFiles : ( Array . isArray ( tailwindConfig . purge )
601
617
? tailwindConfig . purge
602
618
: tailwindConfig . purge . content
@@ -620,25 +636,6 @@ function setupContext(configOrPath) {
620
636
621
637
// ---
622
638
623
- if ( isConfigFile ) {
624
- for ( let dependency of getModuleDependencies ( userConfigPath ) ) {
625
- if ( dependency . file === userConfigPath ) {
626
- continue
627
- }
628
-
629
- context . configDependencies . add ( dependency . file )
630
-
631
- result . messages . push ( {
632
- type : 'dependency' ,
633
- plugin : 'tailwindcss-jit' ,
634
- parent : result . opts . from ,
635
- file : dependency . file ,
636
- } )
637
-
638
- trackModified ( [ dependency . file ] )
639
- }
640
- }
641
-
642
639
let corePluginList = Object . entries ( corePlugins )
643
640
. map ( ( [ name , plugin ] ) => {
644
641
if ( ! tailwindConfig . corePlugins . includes ( name ) ) {
0 commit comments