@vanilla-extract/vite-plugin 3.2.0 → 3.3.1
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.
package/README.md
CHANGED
|
@@ -639,7 +639,7 @@ export const themeB = createTheme(vars, {
|
|
|
639
639
|
});
|
|
640
640
|
```
|
|
641
641
|
|
|
642
|
-
> 💡 All theme
|
|
642
|
+
> 💡 All theme values must be provided or it’s a type error.
|
|
643
643
|
|
|
644
644
|
### createGlobalTheme
|
|
645
645
|
|
|
@@ -662,7 +662,7 @@ export const vars = createGlobalTheme(':root', {
|
|
|
662
662
|
});
|
|
663
663
|
```
|
|
664
664
|
|
|
665
|
-
> 💡 All theme
|
|
665
|
+
> 💡 All theme values must be provided or it’s a type error.
|
|
666
666
|
|
|
667
667
|
If you want to implement an existing theme contract, you can pass it as the second argument.
|
|
668
668
|
|
|
@@ -857,7 +857,7 @@ export const exampleStyle = style({
|
|
|
857
857
|
});
|
|
858
858
|
```
|
|
859
859
|
|
|
860
|
-
Scoped variables can be set
|
|
860
|
+
Scoped variables can be set using the `vars` key.
|
|
861
861
|
|
|
862
862
|
```ts
|
|
863
863
|
import { createVar, style } from '@vanilla-extract/css';
|
|
@@ -113,56 +113,65 @@ function vanillaExtractPlugin({
|
|
|
113
113
|
},
|
|
114
114
|
|
|
115
115
|
resolveId(source) {
|
|
116
|
-
|
|
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(
|
|
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
|
-
|
|
129
|
+
// Keep the original query string for HMR.
|
|
130
|
+
return absoluteId + (query ? `?${query}` : '');
|
|
128
131
|
}
|
|
129
132
|
},
|
|
130
133
|
|
|
131
134
|
load(id) {
|
|
132
|
-
|
|
135
|
+
const [validId] = id.split('?');
|
|
136
|
+
|
|
137
|
+
if (!cssMap.has(validId)) {
|
|
133
138
|
return;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
const css = cssMap.get(
|
|
141
|
+
const css = cssMap.get(validId);
|
|
137
142
|
|
|
138
143
|
if (typeof css !== 'string') {
|
|
139
144
|
return;
|
|
140
145
|
}
|
|
141
146
|
|
|
142
|
-
if (!server) {
|
|
147
|
+
if (!server || server.config.isProduction) {
|
|
143
148
|
return css;
|
|
144
149
|
}
|
|
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:
|
|
156
|
+
filePath: validId
|
|
152
157
|
})},
|
|
153
158
|
css
|
|
154
159
|
});
|
|
155
160
|
|
|
156
161
|
inject(${JSON.stringify(css)});
|
|
157
162
|
|
|
158
|
-
import.meta.hot
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
if (import.meta.hot) {
|
|
164
|
+
import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
|
|
165
|
+
inject(css);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
161
168
|
`;
|
|
162
169
|
},
|
|
163
170
|
|
|
164
171
|
async transform(code, id, ssrParam) {
|
|
165
|
-
|
|
172
|
+
const [validId] = id.split('?');
|
|
173
|
+
|
|
174
|
+
if (!integration.cssFileFilter.test(validId)) {
|
|
166
175
|
return null;
|
|
167
176
|
}
|
|
168
177
|
|
|
@@ -174,10 +183,7 @@ function vanillaExtractPlugin({
|
|
|
174
183
|
ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
|
|
175
184
|
}
|
|
176
185
|
|
|
177
|
-
|
|
178
|
-
const validId = index === -1 ? id : id.substring(0, index);
|
|
179
|
-
|
|
180
|
-
if (ssr) {
|
|
186
|
+
if (ssr && !process.env.VITE_RSC_BUILD) {
|
|
181
187
|
return integration.addFileScope({
|
|
182
188
|
source: code,
|
|
183
189
|
filePath: vite.normalizePath(validId),
|
|
@@ -198,7 +204,7 @@ function vanillaExtractPlugin({
|
|
|
198
204
|
for (const file of watchFiles) {
|
|
199
205
|
// In start mode, we need to prevent the file from rewatching itself.
|
|
200
206
|
// If it's a `build --watch`, it needs to watch everything.
|
|
201
|
-
if (config.command === 'build' || file !==
|
|
207
|
+
if (config.command === 'build' || file !== validId) {
|
|
202
208
|
this.addWatchFile(file);
|
|
203
209
|
}
|
|
204
210
|
}
|
|
@@ -227,10 +233,12 @@ function vanillaExtractPlugin({
|
|
|
227
233
|
const {
|
|
228
234
|
moduleGraph
|
|
229
235
|
} = server;
|
|
230
|
-
const module = moduleGraph.
|
|
236
|
+
const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
|
|
231
237
|
|
|
232
238
|
if (module) {
|
|
233
|
-
moduleGraph.invalidateModule(module);
|
|
239
|
+
moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
|
|
240
|
+
|
|
241
|
+
module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
|
|
234
242
|
}
|
|
235
243
|
|
|
236
244
|
server.ws.send({
|
|
@@ -113,56 +113,65 @@ function vanillaExtractPlugin({
|
|
|
113
113
|
},
|
|
114
114
|
|
|
115
115
|
resolveId(source) {
|
|
116
|
-
|
|
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(
|
|
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
|
-
|
|
129
|
+
// Keep the original query string for HMR.
|
|
130
|
+
return absoluteId + (query ? `?${query}` : '');
|
|
128
131
|
}
|
|
129
132
|
},
|
|
130
133
|
|
|
131
134
|
load(id) {
|
|
132
|
-
|
|
135
|
+
const [validId] = id.split('?');
|
|
136
|
+
|
|
137
|
+
if (!cssMap.has(validId)) {
|
|
133
138
|
return;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
const css = cssMap.get(
|
|
141
|
+
const css = cssMap.get(validId);
|
|
137
142
|
|
|
138
143
|
if (typeof css !== 'string') {
|
|
139
144
|
return;
|
|
140
145
|
}
|
|
141
146
|
|
|
142
|
-
if (!server) {
|
|
147
|
+
if (!server || server.config.isProduction) {
|
|
143
148
|
return css;
|
|
144
149
|
}
|
|
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:
|
|
156
|
+
filePath: validId
|
|
152
157
|
})},
|
|
153
158
|
css
|
|
154
159
|
});
|
|
155
160
|
|
|
156
161
|
inject(${JSON.stringify(css)});
|
|
157
162
|
|
|
158
|
-
import.meta.hot
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
if (import.meta.hot) {
|
|
164
|
+
import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
|
|
165
|
+
inject(css);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
161
168
|
`;
|
|
162
169
|
},
|
|
163
170
|
|
|
164
171
|
async transform(code, id, ssrParam) {
|
|
165
|
-
|
|
172
|
+
const [validId] = id.split('?');
|
|
173
|
+
|
|
174
|
+
if (!integration.cssFileFilter.test(validId)) {
|
|
166
175
|
return null;
|
|
167
176
|
}
|
|
168
177
|
|
|
@@ -174,10 +183,7 @@ function vanillaExtractPlugin({
|
|
|
174
183
|
ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
|
|
175
184
|
}
|
|
176
185
|
|
|
177
|
-
|
|
178
|
-
const validId = index === -1 ? id : id.substring(0, index);
|
|
179
|
-
|
|
180
|
-
if (ssr) {
|
|
186
|
+
if (ssr && !process.env.VITE_RSC_BUILD) {
|
|
181
187
|
return integration.addFileScope({
|
|
182
188
|
source: code,
|
|
183
189
|
filePath: vite.normalizePath(validId),
|
|
@@ -198,7 +204,7 @@ function vanillaExtractPlugin({
|
|
|
198
204
|
for (const file of watchFiles) {
|
|
199
205
|
// In start mode, we need to prevent the file from rewatching itself.
|
|
200
206
|
// If it's a `build --watch`, it needs to watch everything.
|
|
201
|
-
if (config.command === 'build' || file !==
|
|
207
|
+
if (config.command === 'build' || file !== validId) {
|
|
202
208
|
this.addWatchFile(file);
|
|
203
209
|
}
|
|
204
210
|
}
|
|
@@ -227,10 +233,12 @@ function vanillaExtractPlugin({
|
|
|
227
233
|
const {
|
|
228
234
|
moduleGraph
|
|
229
235
|
} = server;
|
|
230
|
-
const module = moduleGraph.
|
|
236
|
+
const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
|
|
231
237
|
|
|
232
238
|
if (module) {
|
|
233
|
-
moduleGraph.invalidateModule(module);
|
|
239
|
+
moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
|
|
240
|
+
|
|
241
|
+
module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
|
|
234
242
|
}
|
|
235
243
|
|
|
236
244
|
server.ws.send({
|
|
@@ -86,56 +86,65 @@ function vanillaExtractPlugin({
|
|
|
86
86
|
},
|
|
87
87
|
|
|
88
88
|
resolveId(source) {
|
|
89
|
-
|
|
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(
|
|
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
|
-
|
|
102
|
+
// Keep the original query string for HMR.
|
|
103
|
+
return absoluteId + (query ? `?${query}` : '');
|
|
101
104
|
}
|
|
102
105
|
},
|
|
103
106
|
|
|
104
107
|
load(id) {
|
|
105
|
-
|
|
108
|
+
const [validId] = id.split('?');
|
|
109
|
+
|
|
110
|
+
if (!cssMap.has(validId)) {
|
|
106
111
|
return;
|
|
107
112
|
}
|
|
108
113
|
|
|
109
|
-
const css = cssMap.get(
|
|
114
|
+
const css = cssMap.get(validId);
|
|
110
115
|
|
|
111
116
|
if (typeof css !== 'string') {
|
|
112
117
|
return;
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
if (!server) {
|
|
120
|
+
if (!server || server.config.isProduction) {
|
|
116
121
|
return css;
|
|
117
122
|
}
|
|
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:
|
|
129
|
+
filePath: validId
|
|
125
130
|
})},
|
|
126
131
|
css
|
|
127
132
|
});
|
|
128
133
|
|
|
129
134
|
inject(${JSON.stringify(css)});
|
|
130
135
|
|
|
131
|
-
import.meta.hot
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
if (import.meta.hot) {
|
|
137
|
+
import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
|
|
138
|
+
inject(css);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
134
141
|
`;
|
|
135
142
|
},
|
|
136
143
|
|
|
137
144
|
async transform(code, id, ssrParam) {
|
|
138
|
-
|
|
145
|
+
const [validId] = id.split('?');
|
|
146
|
+
|
|
147
|
+
if (!cssFileFilter.test(validId)) {
|
|
139
148
|
return null;
|
|
140
149
|
}
|
|
141
150
|
|
|
@@ -147,10 +156,7 @@ function vanillaExtractPlugin({
|
|
|
147
156
|
ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
|
|
148
157
|
}
|
|
149
158
|
|
|
150
|
-
|
|
151
|
-
const validId = index === -1 ? id : id.substring(0, index);
|
|
152
|
-
|
|
153
|
-
if (ssr) {
|
|
159
|
+
if (ssr && !process.env.VITE_RSC_BUILD) {
|
|
154
160
|
return addFileScope({
|
|
155
161
|
source: code,
|
|
156
162
|
filePath: normalizePath(validId),
|
|
@@ -171,7 +177,7 @@ function vanillaExtractPlugin({
|
|
|
171
177
|
for (const file of watchFiles) {
|
|
172
178
|
// In start mode, we need to prevent the file from rewatching itself.
|
|
173
179
|
// If it's a `build --watch`, it needs to watch everything.
|
|
174
|
-
if (config.command === 'build' || file !==
|
|
180
|
+
if (config.command === 'build' || file !== validId) {
|
|
175
181
|
this.addWatchFile(file);
|
|
176
182
|
}
|
|
177
183
|
}
|
|
@@ -200,10 +206,12 @@ function vanillaExtractPlugin({
|
|
|
200
206
|
const {
|
|
201
207
|
moduleGraph
|
|
202
208
|
} = server;
|
|
203
|
-
const module = moduleGraph.
|
|
209
|
+
const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
|
|
204
210
|
|
|
205
211
|
if (module) {
|
|
206
|
-
moduleGraph.invalidateModule(module);
|
|
212
|
+
moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
|
|
213
|
+
|
|
214
|
+
module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
server.ws.send({
|
package/package.json
CHANGED