@@ -22,7 +22,7 @@ import { env } from './sharedState'
22
22
let touchDir =
23
23
env . TAILWIND_TOUCH_DIR || path . join ( os . homedir ( ) || os . tmpdir ( ) , '.tailwindcss' , 'touch' )
24
24
25
- if ( ! env . TAILWIND_DISABLE_TOUCH ) {
25
+ if ( env . TAILWIND_MODE === 'watch' ) {
26
26
if ( fs . existsSync ( touchDir ) ) {
27
27
for ( let file of fs . readdirSync ( touchDir ) ) {
28
28
try {
@@ -94,67 +94,58 @@ function rebootWatcher(context, configPath, configDependencies, candidateFiles)
94
94
touch ( touchFile )
95
95
}
96
96
97
- if ( env . TAILWIND_MODE === 'build' ) {
98
- return
99
- }
97
+ let watcher = getWatcher ( context )
100
98
101
- if (
102
- env . TAILWIND_MODE === 'watch' ||
103
- ( env . TAILWIND_MODE === undefined && env . NODE_ENV === 'development' )
104
- ) {
105
- let watcher = getWatcher ( context )
99
+ Promise . resolve ( watcher ? watcher . close ( ) : null ) . then ( ( ) => {
100
+ log . info ( [
101
+ 'Tailwind CSS is watching for changes...' ,
102
+ 'https://tailwindcss.com/docs/just-in-time-mode#watch-mode-and-one-off-builds' ,
103
+ ] )
106
104
107
- Promise . resolve ( watcher ? watcher . close ( ) : null ) . then ( ( ) => {
108
- log . info ( [
109
- 'Tailwind CSS is watching for changes...' ,
110
- 'https://tailwindcss.com/docs/just-in-time-mode#watch-mode-and-one-off-builds' ,
111
- ] )
105
+ watcher = chokidar . watch ( [ ...candidateFiles , ...configDependencies ] , {
106
+ ignoreInitial : true ,
107
+ } )
112
108
113
- watcher = chokidar . watch ( [ ...candidateFiles , ...configDependencies ] , {
114
- ignoreInitial : true ,
115
- } )
109
+ setWatcher ( context , watcher )
116
110
117
- setWatcher ( context , watcher )
111
+ watcher . on ( 'add' , ( file ) => {
112
+ let changedFile = path . resolve ( '.' , file )
113
+ let content = fs . readFileSync ( changedFile , 'utf8' )
114
+ let extension = path . extname ( changedFile ) . slice ( 1 )
115
+ context . changedContent . push ( { content, extension } )
116
+ touch ( touchFile )
117
+ } )
118
118
119
- watcher . on ( 'add' , ( file ) => {
119
+ watcher . on ( 'change' , ( file ) => {
120
+ // If it was a config dependency, touch the config file to trigger a new context.
121
+ // This is not really that clean of a solution but it's the fastest, because we
122
+ // can do a very quick check on each build to see if the config has changed instead
123
+ // of having to get all of the module dependencies and check every timestamp each
124
+ // time.
125
+ if ( configDependencies . has ( file ) ) {
126
+ for ( let dependency of configDependencies ) {
127
+ delete require . cache [ require . resolve ( dependency ) ]
128
+ }
129
+ touch ( configPath )
130
+ } else {
120
131
let changedFile = path . resolve ( '.' , file )
121
132
let content = fs . readFileSync ( changedFile , 'utf8' )
122
133
let extension = path . extname ( changedFile ) . slice ( 1 )
123
134
context . changedContent . push ( { content, extension } )
124
135
touch ( touchFile )
125
- } )
126
-
127
- watcher . on ( 'change' , ( file ) => {
128
- // If it was a config dependency, touch the config file to trigger a new context.
129
- // This is not really that clean of a solution but it's the fastest, because we
130
- // can do a very quick check on each build to see if the config has changed instead
131
- // of having to get all of the module dependencies and check every timestamp each
132
- // time.
133
- if ( configDependencies . has ( file ) ) {
134
- for ( let dependency of configDependencies ) {
135
- delete require . cache [ require . resolve ( dependency ) ]
136
- }
137
- touch ( configPath )
138
- } else {
139
- let changedFile = path . resolve ( '.' , file )
140
- let content = fs . readFileSync ( changedFile , 'utf8' )
141
- let extension = path . extname ( changedFile ) . slice ( 1 )
142
- context . changedContent . push ( { content, extension } )
143
- touch ( touchFile )
144
- }
145
- } )
146
-
147
- watcher . on ( 'unlink' , ( file ) => {
148
- // Touch the config file if any of the dependencies are deleted.
149
- if ( configDependencies . has ( file ) ) {
150
- for ( let dependency of configDependencies ) {
151
- delete require . cache [ require . resolve ( dependency ) ]
152
- }
153
- touch ( configPath )
136
+ }
137
+ } )
138
+
139
+ watcher . on ( 'unlink' , ( file ) => {
140
+ // Touch the config file if any of the dependencies are deleted.
141
+ if ( configDependencies . has ( file ) ) {
142
+ for ( let dependency of configDependencies ) {
143
+ delete require . cache [ require . resolve ( dependency ) ]
154
144
}
155
- } )
145
+ touch ( configPath )
146
+ }
156
147
} )
157
- }
148
+ } )
158
149
}
159
150
160
151
function generateTouchFileName ( ) {
0 commit comments