@vanilla-extract/vite-plugin 3.1.7 → 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.
package/README.md
CHANGED
|
@@ -88,6 +88,7 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
|
|
|
88
88
|
- [Test environments](#test-environments)
|
|
89
89
|
- [Configuration](#configuration)
|
|
90
90
|
- [identifiers](#identifiers)
|
|
91
|
+
- [esbuildOptions](#esbuildoptions)
|
|
91
92
|
- [Styling API](#styling-api)
|
|
92
93
|
- [style](#style)
|
|
93
94
|
- [styleVariants](#stylevariants)
|
|
@@ -393,6 +394,12 @@ Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc)
|
|
|
393
394
|
|
|
394
395
|
Each integration will set a default value based on the configuration options passed to the bundler.
|
|
395
396
|
|
|
397
|
+
### esbuildOptions
|
|
398
|
+
> Only for `esbuild`, `vite` and `rollup` plugins
|
|
399
|
+
|
|
400
|
+
esbuild is used internally to compile `.css.ts` files before evaluating them to extract styles. You can pass additional options here to customize that process.
|
|
401
|
+
Accepts a subset of esbuild build options (`plugins`, `external`, `define` and `loader`), see https://esbuild.github.io/api/#build-api.
|
|
402
|
+
|
|
396
403
|
---
|
|
397
404
|
|
|
398
405
|
## Styling API
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import { IdentifierOption } from '@vanilla-extract/integration';
|
|
2
|
+
import { IdentifierOption, CompileOptions } from '@vanilla-extract/integration';
|
|
3
3
|
interface Options {
|
|
4
4
|
identifiers?: IdentifierOption;
|
|
5
|
+
esbuildOptions?: CompileOptions['esbuildOptions'];
|
|
5
6
|
}
|
|
6
|
-
export declare function vanillaExtractPlugin({ identifiers }?: Options): Plugin;
|
|
7
|
+
export declare function vanillaExtractPlugin({ identifiers, esbuildOptions, }?: Options): Plugin;
|
|
7
8
|
export {};
|
|
@@ -69,7 +69,8 @@ const resolvePostcssConfig = async config => {
|
|
|
69
69
|
const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
|
|
70
70
|
|
|
71
71
|
function vanillaExtractPlugin({
|
|
72
|
-
identifiers
|
|
72
|
+
identifiers,
|
|
73
|
+
esbuildOptions
|
|
73
74
|
} = {}) {
|
|
74
75
|
let config;
|
|
75
76
|
let server;
|
|
@@ -112,56 +113,63 @@ function vanillaExtractPlugin({
|
|
|
112
113
|
},
|
|
113
114
|
|
|
114
115
|
resolveId(source) {
|
|
115
|
-
|
|
116
|
+
const [validId, query] = source.split('?');
|
|
117
|
+
|
|
118
|
+
if (!validId.endsWith(virtualExt)) {
|
|
116
119
|
return;
|
|
117
120
|
} // Absolute paths seem to occur often in monorepos, where files are
|
|
118
121
|
// imported from outside the config root.
|
|
119
122
|
|
|
120
123
|
|
|
121
|
-
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.
|
|
122
125
|
// The only valid scenario for a missing one is if someone had written
|
|
123
126
|
// a file in their app using the .vanilla.js/.vanilla.css extension
|
|
124
127
|
|
|
125
128
|
if (cssMap.has(absoluteId)) {
|
|
126
|
-
|
|
129
|
+
// Keep the original query string for HMR.
|
|
130
|
+
return absoluteId + (query ? `?${query}` : '');
|
|
127
131
|
}
|
|
128
132
|
},
|
|
129
133
|
|
|
130
134
|
load(id) {
|
|
131
|
-
|
|
135
|
+
const [validId] = id.split('?');
|
|
136
|
+
|
|
137
|
+
if (!cssMap.has(validId)) {
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
140
|
|
|
135
|
-
const css = cssMap.get(
|
|
141
|
+
const css = cssMap.get(validId);
|
|
136
142
|
|
|
137
143
|
if (typeof css !== 'string') {
|
|
138
144
|
return;
|
|
139
145
|
}
|
|
140
146
|
|
|
141
|
-
if (!server) {
|
|
147
|
+
if (!server || server.config.isProduction) {
|
|
142
148
|
return css;
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
return outdent__default["default"]`
|
|
146
152
|
import { injectStyles } from '@vanilla-extract/css/injectStyles';
|
|
147
|
-
|
|
153
|
+
|
|
148
154
|
const inject = (css) => injectStyles({
|
|
149
155
|
fileScope: ${JSON.stringify({
|
|
150
|
-
filePath:
|
|
156
|
+
filePath: validId
|
|
151
157
|
})},
|
|
152
158
|
css
|
|
153
159
|
});
|
|
154
160
|
|
|
155
161
|
inject(${JSON.stringify(css)});
|
|
156
162
|
|
|
157
|
-
import.meta.hot.on('${styleUpdateEvent(
|
|
163
|
+
import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
|
|
158
164
|
inject(css);
|
|
159
|
-
});
|
|
165
|
+
});
|
|
160
166
|
`;
|
|
161
167
|
},
|
|
162
168
|
|
|
163
169
|
async transform(code, id, ssrParam) {
|
|
164
|
-
|
|
170
|
+
const [validId] = id.split('?');
|
|
171
|
+
|
|
172
|
+
if (!integration.cssFileFilter.test(validId)) {
|
|
165
173
|
return null;
|
|
166
174
|
}
|
|
167
175
|
|
|
@@ -173,10 +181,7 @@ function vanillaExtractPlugin({
|
|
|
173
181
|
ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
|
|
174
182
|
}
|
|
175
183
|
|
|
176
|
-
|
|
177
|
-
const validId = index === -1 ? id : id.substring(0, index);
|
|
178
|
-
|
|
179
|
-
if (ssr) {
|
|
184
|
+
if (ssr && !process.env.VITE_RSC_BUILD) {
|
|
180
185
|
return integration.addFileScope({
|
|
181
186
|
source: code,
|
|
182
187
|
filePath: vite.normalizePath(validId),
|
|
@@ -190,13 +195,14 @@ function vanillaExtractPlugin({
|
|
|
190
195
|
watchFiles
|
|
191
196
|
} = await integration.compile({
|
|
192
197
|
filePath: validId,
|
|
193
|
-
cwd: config.root
|
|
198
|
+
cwd: config.root,
|
|
199
|
+
esbuildOptions
|
|
194
200
|
});
|
|
195
201
|
|
|
196
202
|
for (const file of watchFiles) {
|
|
197
203
|
// In start mode, we need to prevent the file from rewatching itself.
|
|
198
204
|
// If it's a `build --watch`, it needs to watch everything.
|
|
199
|
-
if (config.command === 'build' || file !==
|
|
205
|
+
if (config.command === 'build' || file !== validId) {
|
|
200
206
|
this.addWatchFile(file);
|
|
201
207
|
}
|
|
202
208
|
}
|
|
@@ -225,10 +231,12 @@ function vanillaExtractPlugin({
|
|
|
225
231
|
const {
|
|
226
232
|
moduleGraph
|
|
227
233
|
} = server;
|
|
228
|
-
const module = moduleGraph.
|
|
234
|
+
const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
|
|
229
235
|
|
|
230
236
|
if (module) {
|
|
231
|
-
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();
|
|
232
240
|
}
|
|
233
241
|
|
|
234
242
|
server.ws.send({
|
|
@@ -69,7 +69,8 @@ const resolvePostcssConfig = async config => {
|
|
|
69
69
|
const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
|
|
70
70
|
|
|
71
71
|
function vanillaExtractPlugin({
|
|
72
|
-
identifiers
|
|
72
|
+
identifiers,
|
|
73
|
+
esbuildOptions
|
|
73
74
|
} = {}) {
|
|
74
75
|
let config;
|
|
75
76
|
let server;
|
|
@@ -112,56 +113,63 @@ function vanillaExtractPlugin({
|
|
|
112
113
|
},
|
|
113
114
|
|
|
114
115
|
resolveId(source) {
|
|
115
|
-
|
|
116
|
+
const [validId, query] = source.split('?');
|
|
117
|
+
|
|
118
|
+
if (!validId.endsWith(virtualExt)) {
|
|
116
119
|
return;
|
|
117
120
|
} // Absolute paths seem to occur often in monorepos, where files are
|
|
118
121
|
// imported from outside the config root.
|
|
119
122
|
|
|
120
123
|
|
|
121
|
-
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.
|
|
122
125
|
// The only valid scenario for a missing one is if someone had written
|
|
123
126
|
// a file in their app using the .vanilla.js/.vanilla.css extension
|
|
124
127
|
|
|
125
128
|
if (cssMap.has(absoluteId)) {
|
|
126
|
-
|
|
129
|
+
// Keep the original query string for HMR.
|
|
130
|
+
return absoluteId + (query ? `?${query}` : '');
|
|
127
131
|
}
|
|
128
132
|
},
|
|
129
133
|
|
|
130
134
|
load(id) {
|
|
131
|
-
|
|
135
|
+
const [validId] = id.split('?');
|
|
136
|
+
|
|
137
|
+
if (!cssMap.has(validId)) {
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
140
|
|
|
135
|
-
const css = cssMap.get(
|
|
141
|
+
const css = cssMap.get(validId);
|
|
136
142
|
|
|
137
143
|
if (typeof css !== 'string') {
|
|
138
144
|
return;
|
|
139
145
|
}
|
|
140
146
|
|
|
141
|
-
if (!server) {
|
|
147
|
+
if (!server || server.config.isProduction) {
|
|
142
148
|
return css;
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
return outdent__default["default"]`
|
|
146
152
|
import { injectStyles } from '@vanilla-extract/css/injectStyles';
|
|
147
|
-
|
|
153
|
+
|
|
148
154
|
const inject = (css) => injectStyles({
|
|
149
155
|
fileScope: ${JSON.stringify({
|
|
150
|
-
filePath:
|
|
156
|
+
filePath: validId
|
|
151
157
|
})},
|
|
152
158
|
css
|
|
153
159
|
});
|
|
154
160
|
|
|
155
161
|
inject(${JSON.stringify(css)});
|
|
156
162
|
|
|
157
|
-
import.meta.hot.on('${styleUpdateEvent(
|
|
163
|
+
import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
|
|
158
164
|
inject(css);
|
|
159
|
-
});
|
|
165
|
+
});
|
|
160
166
|
`;
|
|
161
167
|
},
|
|
162
168
|
|
|
163
169
|
async transform(code, id, ssrParam) {
|
|
164
|
-
|
|
170
|
+
const [validId] = id.split('?');
|
|
171
|
+
|
|
172
|
+
if (!integration.cssFileFilter.test(validId)) {
|
|
165
173
|
return null;
|
|
166
174
|
}
|
|
167
175
|
|
|
@@ -173,10 +181,7 @@ function vanillaExtractPlugin({
|
|
|
173
181
|
ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
|
|
174
182
|
}
|
|
175
183
|
|
|
176
|
-
|
|
177
|
-
const validId = index === -1 ? id : id.substring(0, index);
|
|
178
|
-
|
|
179
|
-
if (ssr) {
|
|
184
|
+
if (ssr && !process.env.VITE_RSC_BUILD) {
|
|
180
185
|
return integration.addFileScope({
|
|
181
186
|
source: code,
|
|
182
187
|
filePath: vite.normalizePath(validId),
|
|
@@ -190,13 +195,14 @@ function vanillaExtractPlugin({
|
|
|
190
195
|
watchFiles
|
|
191
196
|
} = await integration.compile({
|
|
192
197
|
filePath: validId,
|
|
193
|
-
cwd: config.root
|
|
198
|
+
cwd: config.root,
|
|
199
|
+
esbuildOptions
|
|
194
200
|
});
|
|
195
201
|
|
|
196
202
|
for (const file of watchFiles) {
|
|
197
203
|
// In start mode, we need to prevent the file from rewatching itself.
|
|
198
204
|
// If it's a `build --watch`, it needs to watch everything.
|
|
199
|
-
if (config.command === 'build' || file !==
|
|
205
|
+
if (config.command === 'build' || file !== validId) {
|
|
200
206
|
this.addWatchFile(file);
|
|
201
207
|
}
|
|
202
208
|
}
|
|
@@ -225,10 +231,12 @@ function vanillaExtractPlugin({
|
|
|
225
231
|
const {
|
|
226
232
|
moduleGraph
|
|
227
233
|
} = server;
|
|
228
|
-
const module = moduleGraph.
|
|
234
|
+
const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
|
|
229
235
|
|
|
230
236
|
if (module) {
|
|
231
|
-
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();
|
|
232
240
|
}
|
|
233
241
|
|
|
234
242
|
server.ws.send({
|
|
@@ -42,7 +42,8 @@ const resolvePostcssConfig = async config => {
|
|
|
42
42
|
const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
|
|
43
43
|
|
|
44
44
|
function vanillaExtractPlugin({
|
|
45
|
-
identifiers
|
|
45
|
+
identifiers,
|
|
46
|
+
esbuildOptions
|
|
46
47
|
} = {}) {
|
|
47
48
|
let config;
|
|
48
49
|
let server;
|
|
@@ -85,56 +86,63 @@ function vanillaExtractPlugin({
|
|
|
85
86
|
},
|
|
86
87
|
|
|
87
88
|
resolveId(source) {
|
|
88
|
-
|
|
89
|
+
const [validId, query] = source.split('?');
|
|
90
|
+
|
|
91
|
+
if (!validId.endsWith(virtualExt)) {
|
|
89
92
|
return;
|
|
90
93
|
} // Absolute paths seem to occur often in monorepos, where files are
|
|
91
94
|
// imported from outside the config root.
|
|
92
95
|
|
|
93
96
|
|
|
94
|
-
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.
|
|
95
98
|
// The only valid scenario for a missing one is if someone had written
|
|
96
99
|
// a file in their app using the .vanilla.js/.vanilla.css extension
|
|
97
100
|
|
|
98
101
|
if (cssMap.has(absoluteId)) {
|
|
99
|
-
|
|
102
|
+
// Keep the original query string for HMR.
|
|
103
|
+
return absoluteId + (query ? `?${query}` : '');
|
|
100
104
|
}
|
|
101
105
|
},
|
|
102
106
|
|
|
103
107
|
load(id) {
|
|
104
|
-
|
|
108
|
+
const [validId] = id.split('?');
|
|
109
|
+
|
|
110
|
+
if (!cssMap.has(validId)) {
|
|
105
111
|
return;
|
|
106
112
|
}
|
|
107
113
|
|
|
108
|
-
const css = cssMap.get(
|
|
114
|
+
const css = cssMap.get(validId);
|
|
109
115
|
|
|
110
116
|
if (typeof css !== 'string') {
|
|
111
117
|
return;
|
|
112
118
|
}
|
|
113
119
|
|
|
114
|
-
if (!server) {
|
|
120
|
+
if (!server || server.config.isProduction) {
|
|
115
121
|
return css;
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
return outdent`
|
|
119
125
|
import { injectStyles } from '@vanilla-extract/css/injectStyles';
|
|
120
|
-
|
|
126
|
+
|
|
121
127
|
const inject = (css) => injectStyles({
|
|
122
128
|
fileScope: ${JSON.stringify({
|
|
123
|
-
filePath:
|
|
129
|
+
filePath: validId
|
|
124
130
|
})},
|
|
125
131
|
css
|
|
126
132
|
});
|
|
127
133
|
|
|
128
134
|
inject(${JSON.stringify(css)});
|
|
129
135
|
|
|
130
|
-
import.meta.hot.on('${styleUpdateEvent(
|
|
136
|
+
import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
|
|
131
137
|
inject(css);
|
|
132
|
-
});
|
|
138
|
+
});
|
|
133
139
|
`;
|
|
134
140
|
},
|
|
135
141
|
|
|
136
142
|
async transform(code, id, ssrParam) {
|
|
137
|
-
|
|
143
|
+
const [validId] = id.split('?');
|
|
144
|
+
|
|
145
|
+
if (!cssFileFilter.test(validId)) {
|
|
138
146
|
return null;
|
|
139
147
|
}
|
|
140
148
|
|
|
@@ -146,10 +154,7 @@ function vanillaExtractPlugin({
|
|
|
146
154
|
ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
|
|
147
155
|
}
|
|
148
156
|
|
|
149
|
-
|
|
150
|
-
const validId = index === -1 ? id : id.substring(0, index);
|
|
151
|
-
|
|
152
|
-
if (ssr) {
|
|
157
|
+
if (ssr && !process.env.VITE_RSC_BUILD) {
|
|
153
158
|
return addFileScope({
|
|
154
159
|
source: code,
|
|
155
160
|
filePath: normalizePath(validId),
|
|
@@ -163,13 +168,14 @@ function vanillaExtractPlugin({
|
|
|
163
168
|
watchFiles
|
|
164
169
|
} = await compile({
|
|
165
170
|
filePath: validId,
|
|
166
|
-
cwd: config.root
|
|
171
|
+
cwd: config.root,
|
|
172
|
+
esbuildOptions
|
|
167
173
|
});
|
|
168
174
|
|
|
169
175
|
for (const file of watchFiles) {
|
|
170
176
|
// In start mode, we need to prevent the file from rewatching itself.
|
|
171
177
|
// If it's a `build --watch`, it needs to watch everything.
|
|
172
|
-
if (config.command === 'build' || file !==
|
|
178
|
+
if (config.command === 'build' || file !== validId) {
|
|
173
179
|
this.addWatchFile(file);
|
|
174
180
|
}
|
|
175
181
|
}
|
|
@@ -198,10 +204,12 @@ function vanillaExtractPlugin({
|
|
|
198
204
|
const {
|
|
199
205
|
moduleGraph
|
|
200
206
|
} = server;
|
|
201
|
-
const module = moduleGraph.
|
|
207
|
+
const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
|
|
202
208
|
|
|
203
209
|
if (module) {
|
|
204
|
-
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();
|
|
205
213
|
}
|
|
206
214
|
|
|
207
215
|
server.ws.send({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanilla-extract/vite-plugin",
|
|
3
|
-
"version": "3.
|
|
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",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "SEEK",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@vanilla-extract/integration": "^
|
|
18
|
+
"@vanilla-extract/integration": "^5.0.0",
|
|
19
19
|
"outdent": "^0.8.0",
|
|
20
20
|
"postcss": "^8.3.6",
|
|
21
21
|
"postcss-load-config": "^3.1.0"
|