@@ -5,8 +5,8 @@ import type {
55 ResolvedConfig ,
66 ConfigEnv ,
77 ViteDevServer ,
8- Rollup ,
98 PluginOption ,
9+ TransformResult ,
1010 UserConfig ,
1111} from 'vite' ;
1212import {
@@ -96,23 +96,6 @@ export function vanillaExtractPlugin({
9696 }
9797 }
9898
99- function addWatchFiles (
100- this : Rollup . PluginContext ,
101- fromId : string ,
102- files : Set < string > ,
103- ) {
104- // We don't need to watch files in build mode
105- if ( config . command === 'build' && ! config . build . watch ) {
106- return ;
107- }
108-
109- for ( const file of files ) {
110- if ( ! file . includes ( 'node_modules' ) && normalizePath ( file ) !== fromId ) {
111- this . addWatchFile ( file ) ;
112- }
113- }
114- }
115-
11699 return {
117100 name : 'vanilla-extract' ,
118101 configureServer ( _server ) {
@@ -210,16 +193,33 @@ export function vanillaExtractPlugin({
210193 absoluteId ,
211194 { outputCss : true } ,
212195 ) ;
213-
214- addWatchFiles . call ( this , absoluteId , watchFiles ) ;
215-
216- // We have to invalidate the virtual module, not the real one we just transformed
217- invalidateModule ( fileIdToVirtualId ( absoluteId ) ) ;
218-
219- return {
196+ const result : TransformResult = {
220197 code : source ,
221198 map : { mappings : '' } ,
222199 } ;
200+
201+ // We don't need to watch files in build mode
202+ if ( config . command === 'build' && ! config . build . watch ) {
203+ return result ;
204+ }
205+
206+ for ( const file of watchFiles ) {
207+ if (
208+ ! file . includes ( 'node_modules' ) &&
209+ normalizePath ( file ) !== absoluteId
210+ ) {
211+ this . addWatchFile ( file ) ;
212+ }
213+
214+ // We have to invalidate the virtual module & deps, not the real one we just transformed
215+ // The deps have to be invalidated in case one of them changing was the trigger causing
216+ // the current transformation
217+ if ( file . endsWith ( '.css.ts' ) ) {
218+ invalidateModule ( fileIdToVirtualId ( file ) ) ;
219+ }
220+ }
221+
222+ return result ;
223223 }
224224 } ,
225225 resolveId ( source ) {
0 commit comments