@vanilla-extract/vite-plugin 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -113,27 +113,32 @@ function vanillaExtractPlugin({
113
113
  },
114
114
 
115
115
  resolveId(source) {
116
- if (!source.endsWith(virtualExt)) {
116
+ const [validId, query] = source.split('?');
117
+
118
+ if (!validId.endsWith(virtualExt)) {
117
119
  return;
118
120
  } // Absolute paths seem to occur often in monorepos, where files are
119
121
  // imported from outside the config root.
120
122
 
121
123
 
122
- const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source); // There should always be an entry in the `cssMap` here.
124
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
123
125
  // The only valid scenario for a missing one is if someone had written
124
126
  // a file in their app using the .vanilla.js/.vanilla.css extension
125
127
 
126
128
  if (cssMap.has(absoluteId)) {
127
- return absoluteId;
129
+ // Keep the original query string for HMR.
130
+ return absoluteId + (query ? `?${query}` : '');
128
131
  }
129
132
  },
130
133
 
131
134
  load(id) {
132
- if (!cssMap.has(id)) {
135
+ const [validId] = id.split('?');
136
+
137
+ if (!cssMap.has(validId)) {
133
138
  return;
134
139
  }
135
140
 
136
- const css = cssMap.get(id);
141
+ const css = cssMap.get(validId);
137
142
 
138
143
  if (typeof css !== 'string') {
139
144
  return;
@@ -145,24 +150,26 @@ function vanillaExtractPlugin({
145
150
 
146
151
  return outdent__default["default"]`
147
152
  import { injectStyles } from '@vanilla-extract/css/injectStyles';
148
-
153
+
149
154
  const inject = (css) => injectStyles({
150
155
  fileScope: ${JSON.stringify({
151
- filePath: id
156
+ filePath: validId
152
157
  })},
153
158
  css
154
159
  });
155
160
 
156
161
  inject(${JSON.stringify(css)});
157
162
 
158
- import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {
163
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
159
164
  inject(css);
160
- });
165
+ });
161
166
  `;
162
167
  },
163
168
 
164
169
  async transform(code, id, ssrParam) {
165
- if (!integration.cssFileFilter.test(id)) {
170
+ const [validId] = id.split('?');
171
+
172
+ if (!integration.cssFileFilter.test(validId)) {
166
173
  return null;
167
174
  }
168
175
 
@@ -174,10 +181,7 @@ function vanillaExtractPlugin({
174
181
  ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
175
182
  }
176
183
 
177
- const index = id.indexOf('?');
178
- const validId = index === -1 ? id : id.substring(0, index);
179
-
180
- if (ssr) {
184
+ if (ssr && !process.env.VITE_RSC_BUILD) {
181
185
  return integration.addFileScope({
182
186
  source: code,
183
187
  filePath: vite.normalizePath(validId),
@@ -198,7 +202,7 @@ function vanillaExtractPlugin({
198
202
  for (const file of watchFiles) {
199
203
  // In start mode, we need to prevent the file from rewatching itself.
200
204
  // If it's a `build --watch`, it needs to watch everything.
201
- if (config.command === 'build' || file !== id) {
205
+ if (config.command === 'build' || file !== validId) {
202
206
  this.addWatchFile(file);
203
207
  }
204
208
  }
@@ -227,10 +231,12 @@ function vanillaExtractPlugin({
227
231
  const {
228
232
  moduleGraph
229
233
  } = server;
230
- const module = moduleGraph.getModuleById(absoluteId);
234
+ const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
231
235
 
232
236
  if (module) {
233
- moduleGraph.invalidateModule(module);
237
+ moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
238
+
239
+ module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
234
240
  }
235
241
 
236
242
  server.ws.send({
@@ -113,27 +113,32 @@ function vanillaExtractPlugin({
113
113
  },
114
114
 
115
115
  resolveId(source) {
116
- if (!source.endsWith(virtualExt)) {
116
+ const [validId, query] = source.split('?');
117
+
118
+ if (!validId.endsWith(virtualExt)) {
117
119
  return;
118
120
  } // Absolute paths seem to occur often in monorepos, where files are
119
121
  // imported from outside the config root.
120
122
 
121
123
 
122
- const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source); // There should always be an entry in the `cssMap` here.
124
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
123
125
  // The only valid scenario for a missing one is if someone had written
124
126
  // a file in their app using the .vanilla.js/.vanilla.css extension
125
127
 
126
128
  if (cssMap.has(absoluteId)) {
127
- return absoluteId;
129
+ // Keep the original query string for HMR.
130
+ return absoluteId + (query ? `?${query}` : '');
128
131
  }
129
132
  },
130
133
 
131
134
  load(id) {
132
- if (!cssMap.has(id)) {
135
+ const [validId] = id.split('?');
136
+
137
+ if (!cssMap.has(validId)) {
133
138
  return;
134
139
  }
135
140
 
136
- const css = cssMap.get(id);
141
+ const css = cssMap.get(validId);
137
142
 
138
143
  if (typeof css !== 'string') {
139
144
  return;
@@ -145,24 +150,26 @@ function vanillaExtractPlugin({
145
150
 
146
151
  return outdent__default["default"]`
147
152
  import { injectStyles } from '@vanilla-extract/css/injectStyles';
148
-
153
+
149
154
  const inject = (css) => injectStyles({
150
155
  fileScope: ${JSON.stringify({
151
- filePath: id
156
+ filePath: validId
152
157
  })},
153
158
  css
154
159
  });
155
160
 
156
161
  inject(${JSON.stringify(css)});
157
162
 
158
- import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {
163
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
159
164
  inject(css);
160
- });
165
+ });
161
166
  `;
162
167
  },
163
168
 
164
169
  async transform(code, id, ssrParam) {
165
- if (!integration.cssFileFilter.test(id)) {
170
+ const [validId] = id.split('?');
171
+
172
+ if (!integration.cssFileFilter.test(validId)) {
166
173
  return null;
167
174
  }
168
175
 
@@ -174,10 +181,7 @@ function vanillaExtractPlugin({
174
181
  ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
175
182
  }
176
183
 
177
- const index = id.indexOf('?');
178
- const validId = index === -1 ? id : id.substring(0, index);
179
-
180
- if (ssr) {
184
+ if (ssr && !process.env.VITE_RSC_BUILD) {
181
185
  return integration.addFileScope({
182
186
  source: code,
183
187
  filePath: vite.normalizePath(validId),
@@ -198,7 +202,7 @@ function vanillaExtractPlugin({
198
202
  for (const file of watchFiles) {
199
203
  // In start mode, we need to prevent the file from rewatching itself.
200
204
  // If it's a `build --watch`, it needs to watch everything.
201
- if (config.command === 'build' || file !== id) {
205
+ if (config.command === 'build' || file !== validId) {
202
206
  this.addWatchFile(file);
203
207
  }
204
208
  }
@@ -227,10 +231,12 @@ function vanillaExtractPlugin({
227
231
  const {
228
232
  moduleGraph
229
233
  } = server;
230
- const module = moduleGraph.getModuleById(absoluteId);
234
+ const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
231
235
 
232
236
  if (module) {
233
- moduleGraph.invalidateModule(module);
237
+ moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
238
+
239
+ module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
234
240
  }
235
241
 
236
242
  server.ws.send({
@@ -86,27 +86,32 @@ function vanillaExtractPlugin({
86
86
  },
87
87
 
88
88
  resolveId(source) {
89
- if (!source.endsWith(virtualExt)) {
89
+ const [validId, query] = source.split('?');
90
+
91
+ if (!validId.endsWith(virtualExt)) {
90
92
  return;
91
93
  } // Absolute paths seem to occur often in monorepos, where files are
92
94
  // imported from outside the config root.
93
95
 
94
96
 
95
- const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source); // There should always be an entry in the `cssMap` here.
97
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
96
98
  // The only valid scenario for a missing one is if someone had written
97
99
  // a file in their app using the .vanilla.js/.vanilla.css extension
98
100
 
99
101
  if (cssMap.has(absoluteId)) {
100
- return absoluteId;
102
+ // Keep the original query string for HMR.
103
+ return absoluteId + (query ? `?${query}` : '');
101
104
  }
102
105
  },
103
106
 
104
107
  load(id) {
105
- if (!cssMap.has(id)) {
108
+ const [validId] = id.split('?');
109
+
110
+ if (!cssMap.has(validId)) {
106
111
  return;
107
112
  }
108
113
 
109
- const css = cssMap.get(id);
114
+ const css = cssMap.get(validId);
110
115
 
111
116
  if (typeof css !== 'string') {
112
117
  return;
@@ -118,24 +123,26 @@ function vanillaExtractPlugin({
118
123
 
119
124
  return outdent`
120
125
  import { injectStyles } from '@vanilla-extract/css/injectStyles';
121
-
126
+
122
127
  const inject = (css) => injectStyles({
123
128
  fileScope: ${JSON.stringify({
124
- filePath: id
129
+ filePath: validId
125
130
  })},
126
131
  css
127
132
  });
128
133
 
129
134
  inject(${JSON.stringify(css)});
130
135
 
131
- import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {
136
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
132
137
  inject(css);
133
- });
138
+ });
134
139
  `;
135
140
  },
136
141
 
137
142
  async transform(code, id, ssrParam) {
138
- if (!cssFileFilter.test(id)) {
143
+ const [validId] = id.split('?');
144
+
145
+ if (!cssFileFilter.test(validId)) {
139
146
  return null;
140
147
  }
141
148
 
@@ -147,10 +154,7 @@ function vanillaExtractPlugin({
147
154
  ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
148
155
  }
149
156
 
150
- const index = id.indexOf('?');
151
- const validId = index === -1 ? id : id.substring(0, index);
152
-
153
- if (ssr) {
157
+ if (ssr && !process.env.VITE_RSC_BUILD) {
154
158
  return addFileScope({
155
159
  source: code,
156
160
  filePath: normalizePath(validId),
@@ -171,7 +175,7 @@ function vanillaExtractPlugin({
171
175
  for (const file of watchFiles) {
172
176
  // In start mode, we need to prevent the file from rewatching itself.
173
177
  // If it's a `build --watch`, it needs to watch everything.
174
- if (config.command === 'build' || file !== id) {
178
+ if (config.command === 'build' || file !== validId) {
175
179
  this.addWatchFile(file);
176
180
  }
177
181
  }
@@ -200,10 +204,12 @@ function vanillaExtractPlugin({
200
204
  const {
201
205
  moduleGraph
202
206
  } = server;
203
- const module = moduleGraph.getModuleById(absoluteId);
207
+ const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
204
208
 
205
209
  if (module) {
206
- moduleGraph.invalidateModule(module);
210
+ moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
211
+
212
+ module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
207
213
  }
208
214
 
209
215
  server.ws.send({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanilla-extract/vite-plugin",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "description": "Zero-runtime Stylesheets-in-TypeScript",
5
5
  "main": "dist/vanilla-extract-vite-plugin.cjs.js",
6
6
  "module": "dist/vanilla-extract-vite-plugin.esm.js",