@@ -5,8 +5,8 @@ import type {
5
5
ResolvedConfig ,
6
6
ConfigEnv ,
7
7
ViteDevServer ,
8
- Rollup ,
9
8
PluginOption ,
9
+ TransformResult ,
10
10
UserConfig ,
11
11
} from 'vite' ;
12
12
import {
@@ -96,23 +96,6 @@ export function vanillaExtractPlugin({
96
96
}
97
97
}
98
98
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
-
116
99
return {
117
100
name : 'vanilla-extract' ,
118
101
configureServer ( _server ) {
@@ -210,16 +193,33 @@ export function vanillaExtractPlugin({
210
193
absoluteId ,
211
194
{ outputCss : true } ,
212
195
) ;
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 = {
220
197
code : source ,
221
198
map : { mappings : '' } ,
222
199
} ;
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 ;
223
223
}
224
224
} ,
225
225
resolveId ( source ) {
0 commit comments