@@ -22,7 +22,7 @@ import { env } from './sharedState'
2222let touchDir =
2323 env . TAILWIND_TOUCH_DIR || path . join ( os . homedir ( ) || os . tmpdir ( ) , '.tailwindcss' , 'touch' )
2424
25- if ( ! env . TAILWIND_DISABLE_TOUCH ) {
25+ if ( env . TAILWIND_MODE === 'watch' ) {
2626 if ( fs . existsSync ( touchDir ) ) {
2727 for ( let file of fs . readdirSync ( touchDir ) ) {
2828 try {
@@ -94,67 +94,58 @@ function rebootWatcher(context, configPath, configDependencies, candidateFiles)
9494 touch ( touchFile )
9595 }
9696
97- if ( env . TAILWIND_MODE === 'build' ) {
98- return
99- }
97+ let watcher = getWatcher ( context )
10098
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+ ] )
106104
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+ } )
112108
113- watcher = chokidar . watch ( [ ...candidateFiles , ...configDependencies ] , {
114- ignoreInitial : true ,
115- } )
109+ setWatcher ( context , watcher )
116110
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+ } )
118118
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 {
120131 let changedFile = path . resolve ( '.' , file )
121132 let content = fs . readFileSync ( changedFile , 'utf8' )
122133 let extension = path . extname ( changedFile ) . slice ( 1 )
123134 context . changedContent . push ( { content, extension } )
124135 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 ) ]
154144 }
155- } )
145+ touch ( configPath )
146+ }
156147 } )
157- }
148+ } )
158149}
159150
160151function generateTouchFileName ( ) {
0 commit comments