@vanilla-extract/vite-plugin 3.7.0 → 3.8.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.
@@ -3,8 +3,9 @@ import { IdentifierOption, CompileOptions } from '@vanilla-extract/integration';
3
3
 
4
4
  interface Options {
5
5
  identifiers?: IdentifierOption;
6
+ emitCssInSsr?: boolean;
6
7
  esbuildOptions?: CompileOptions['esbuildOptions'];
7
8
  }
8
- declare function vanillaExtractPlugin({ identifiers, esbuildOptions, }?: Options): Plugin;
9
+ declare function vanillaExtractPlugin({ identifiers, emitCssInSsr, esbuildOptions, }?: Options): Plugin;
9
10
 
10
11
  export { vanillaExtractPlugin };
@@ -34,13 +34,12 @@ var outdent__default = /*#__PURE__*/_interopDefault(outdent);
34
34
  // https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts
35
35
  const resolvePostcssConfig = async config => {
36
36
  var _config$css;
37
-
38
37
  // inline postcss config via vite config
39
38
  const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss;
40
39
  const inlineOptionsIsString = typeof inlineOptions === 'string';
41
-
42
40
  if (inlineOptions && !inlineOptionsIsString) {
43
- const options = { ...inlineOptions
41
+ const options = {
42
+ ...inlineOptions
44
43
  };
45
44
  delete options.plugins;
46
45
  return {
@@ -60,37 +59,33 @@ const resolvePostcssConfig = async config => {
60
59
  if (!/No PostCSS Config found/.test(e.message)) {
61
60
  throw e;
62
61
  }
63
-
64
62
  return null;
65
63
  }
66
64
  }
67
65
  };
68
66
 
69
67
  const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
70
-
71
68
  const virtualExtCss = '.vanilla.css';
72
69
  const virtualExtJs = '.vanilla.js';
73
70
  function vanillaExtractPlugin({
74
71
  identifiers,
72
+ emitCssInSsr,
75
73
  esbuildOptions
76
74
  } = {}) {
77
75
  let config;
78
76
  let server;
79
77
  let postCssConfig;
80
78
  const cssMap = new Map();
81
- let forceEmitCssInSsrBuild = !!process.env.VITE_RSC_BUILD;
79
+ const hasEmitCssOverride = typeof emitCssInSsr === 'boolean';
80
+ let resolvedEmitCssInSsr = hasEmitCssOverride ? emitCssInSsr : !!process.env.VITE_RSC_BUILD;
82
81
  let packageName;
83
-
84
82
  const getAbsoluteVirtualFileId = source => vite.normalizePath(path__default["default"].join(config.root, source));
85
-
86
83
  return {
87
84
  name: 'vanilla-extract',
88
85
  enforce: 'pre',
89
-
90
86
  configureServer(_server) {
91
87
  server = _server;
92
88
  },
93
-
94
89
  config(_userConfig, env) {
95
90
  const include = env.command === 'serve' ? ['@vanilla-extract/css/injectStyles'] : [];
96
91
  return {
@@ -102,56 +97,46 @@ function vanillaExtractPlugin({
102
97
  }
103
98
  };
104
99
  },
105
-
106
100
  async configResolved(resolvedConfig) {
107
101
  config = resolvedConfig;
108
102
  packageName = integration.getPackageInfo(config.root).name;
109
-
110
103
  if (config.command === 'serve') {
111
104
  postCssConfig = await resolvePostcssConfig(config);
112
105
  }
113
-
114
- if (config.plugins.some(plugin => ['astro:build', 'solid-start-server', 'vite-plugin-qwik'].includes(plugin.name))) {
115
- forceEmitCssInSsrBuild = true;
106
+ if (!hasEmitCssOverride && config.plugins.some(plugin => ['astro:build', 'solid-start-server', 'vite-plugin-qwik', 'vite-plugin-svelte'].includes(plugin.name))) {
107
+ resolvedEmitCssInSsr = true;
116
108
  }
117
109
  },
118
-
119
110
  resolveId(source) {
120
111
  const [validId, query] = source.split('?');
121
-
122
112
  if (!validId.endsWith(virtualExtCss) && !validId.endsWith(virtualExtJs)) {
123
113
  return;
124
- } // Absolute paths seem to occur often in monorepos, where files are
125
- // imported from outside the config root.
114
+ }
126
115
 
116
+ // Absolute paths seem to occur often in monorepos, where files are
117
+ // imported from outside the config root.
118
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
127
119
 
128
- const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
120
+ // There should always be an entry in the `cssMap` here.
129
121
  // The only valid scenario for a missing one is if someone had written
130
122
  // a file in their app using the .vanilla.js/.vanilla.css extension
131
-
132
123
  if (cssMap.has(absoluteId)) {
133
124
  // Keep the original query string for HMR.
134
125
  return absoluteId + (query ? `?${query}` : '');
135
126
  }
136
127
  },
137
-
138
128
  load(id) {
139
129
  const [validId] = id.split('?');
140
-
141
130
  if (!cssMap.has(validId)) {
142
131
  return;
143
132
  }
144
-
145
133
  const css = cssMap.get(validId);
146
-
147
134
  if (typeof css !== 'string') {
148
135
  return;
149
136
  }
150
-
151
137
  if (validId.endsWith(virtualExtCss)) {
152
138
  return css;
153
139
  }
154
-
155
140
  return outdent__default["default"]`
156
141
  import { injectStyles } from '@vanilla-extract/css/injectStyles';
157
142
 
@@ -171,24 +156,19 @@ function vanillaExtractPlugin({
171
156
  }
172
157
  `;
173
158
  },
174
-
175
159
  async transform(code, id, ssrParam) {
176
160
  const [validId] = id.split('?');
177
-
178
161
  if (!integration.cssFileFilter.test(validId)) {
179
162
  return null;
180
163
  }
181
-
182
164
  const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug';
183
165
  let ssr;
184
-
185
166
  if (typeof ssrParam === 'boolean') {
186
167
  ssr = ssrParam;
187
168
  } else {
188
169
  ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
189
170
  }
190
-
191
- if (ssr && !forceEmitCssInSsrBuild) {
171
+ if (ssr && !resolvedEmitCssInSsr) {
192
172
  return integration.transform({
193
173
  source: code,
194
174
  filePath: vite.normalizePath(validId),
@@ -197,7 +177,6 @@ function vanillaExtractPlugin({
197
177
  identOption
198
178
  });
199
179
  }
200
-
201
180
  const {
202
181
  source,
203
182
  watchFiles
@@ -207,7 +186,6 @@ function vanillaExtractPlugin({
207
186
  esbuildOptions,
208
187
  identOption
209
188
  });
210
-
211
189
  for (const file of watchFiles) {
212
190
  // In start mode, we need to prevent the file from rewatching itself.
213
191
  // If it's a `build --watch`, it needs to watch everything.
@@ -215,7 +193,6 @@ function vanillaExtractPlugin({
215
193
  this.addWatchFile(file);
216
194
  }
217
195
  }
218
-
219
196
  const output = await integration.processVanillaFile({
220
197
  source,
221
198
  filePath: validId,
@@ -224,40 +201,38 @@ function vanillaExtractPlugin({
224
201
  fileScope,
225
202
  source
226
203
  }) => {
227
- const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && forceEmitCssInSsrBuild ? virtualExtCss : virtualExtJs}`;
204
+ const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && resolvedEmitCssInSsr ? virtualExtCss : virtualExtJs}`;
228
205
  const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
229
206
  let cssSource = source;
230
-
231
207
  if (postCssConfig) {
232
- const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(source, { ...postCssConfig.options,
208
+ const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(source, {
209
+ ...postCssConfig.options,
233
210
  from: undefined,
234
211
  map: false
235
212
  });
236
213
  cssSource = postCssResult.css;
237
214
  }
238
-
239
215
  if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
240
216
  const {
241
217
  moduleGraph
242
218
  } = server;
243
219
  const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
244
-
245
220
  if (module) {
246
- moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
221
+ moduleGraph.invalidateModule(module);
247
222
 
223
+ // Vite uses this timestamp to add `?t=` query string automatically for HMR.
248
224
  module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
249
225
  }
250
-
251
226
  server.ws.send({
252
227
  type: 'custom',
253
228
  event: styleUpdateEvent(absoluteId),
254
229
  data: cssSource
255
230
  });
256
231
  }
232
+ cssMap.set(absoluteId, cssSource);
257
233
 
258
- cssMap.set(absoluteId, cssSource); // We use the root relative id here to ensure file contents (content-hashes)
234
+ // We use the root relative id here to ensure file contents (content-hashes)
259
235
  // are consistent across build machines
260
-
261
236
  return `import "${rootRelativeId}";`;
262
237
  }
263
238
  });
@@ -268,7 +243,6 @@ function vanillaExtractPlugin({
268
243
  }
269
244
  };
270
245
  }
271
-
272
246
  };
273
247
  }
274
248
 
@@ -34,13 +34,12 @@ var outdent__default = /*#__PURE__*/_interopDefault(outdent);
34
34
  // https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts
35
35
  const resolvePostcssConfig = async config => {
36
36
  var _config$css;
37
-
38
37
  // inline postcss config via vite config
39
38
  const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss;
40
39
  const inlineOptionsIsString = typeof inlineOptions === 'string';
41
-
42
40
  if (inlineOptions && !inlineOptionsIsString) {
43
- const options = { ...inlineOptions
41
+ const options = {
42
+ ...inlineOptions
44
43
  };
45
44
  delete options.plugins;
46
45
  return {
@@ -60,37 +59,33 @@ const resolvePostcssConfig = async config => {
60
59
  if (!/No PostCSS Config found/.test(e.message)) {
61
60
  throw e;
62
61
  }
63
-
64
62
  return null;
65
63
  }
66
64
  }
67
65
  };
68
66
 
69
67
  const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
70
-
71
68
  const virtualExtCss = '.vanilla.css';
72
69
  const virtualExtJs = '.vanilla.js';
73
70
  function vanillaExtractPlugin({
74
71
  identifiers,
72
+ emitCssInSsr,
75
73
  esbuildOptions
76
74
  } = {}) {
77
75
  let config;
78
76
  let server;
79
77
  let postCssConfig;
80
78
  const cssMap = new Map();
81
- let forceEmitCssInSsrBuild = !!process.env.VITE_RSC_BUILD;
79
+ const hasEmitCssOverride = typeof emitCssInSsr === 'boolean';
80
+ let resolvedEmitCssInSsr = hasEmitCssOverride ? emitCssInSsr : !!process.env.VITE_RSC_BUILD;
82
81
  let packageName;
83
-
84
82
  const getAbsoluteVirtualFileId = source => vite.normalizePath(path__default["default"].join(config.root, source));
85
-
86
83
  return {
87
84
  name: 'vanilla-extract',
88
85
  enforce: 'pre',
89
-
90
86
  configureServer(_server) {
91
87
  server = _server;
92
88
  },
93
-
94
89
  config(_userConfig, env) {
95
90
  const include = env.command === 'serve' ? ['@vanilla-extract/css/injectStyles'] : [];
96
91
  return {
@@ -102,56 +97,46 @@ function vanillaExtractPlugin({
102
97
  }
103
98
  };
104
99
  },
105
-
106
100
  async configResolved(resolvedConfig) {
107
101
  config = resolvedConfig;
108
102
  packageName = integration.getPackageInfo(config.root).name;
109
-
110
103
  if (config.command === 'serve') {
111
104
  postCssConfig = await resolvePostcssConfig(config);
112
105
  }
113
-
114
- if (config.plugins.some(plugin => ['astro:build', 'solid-start-server', 'vite-plugin-qwik'].includes(plugin.name))) {
115
- forceEmitCssInSsrBuild = true;
106
+ if (!hasEmitCssOverride && config.plugins.some(plugin => ['astro:build', 'solid-start-server', 'vite-plugin-qwik', 'vite-plugin-svelte'].includes(plugin.name))) {
107
+ resolvedEmitCssInSsr = true;
116
108
  }
117
109
  },
118
-
119
110
  resolveId(source) {
120
111
  const [validId, query] = source.split('?');
121
-
122
112
  if (!validId.endsWith(virtualExtCss) && !validId.endsWith(virtualExtJs)) {
123
113
  return;
124
- } // Absolute paths seem to occur often in monorepos, where files are
125
- // imported from outside the config root.
114
+ }
126
115
 
116
+ // Absolute paths seem to occur often in monorepos, where files are
117
+ // imported from outside the config root.
118
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
127
119
 
128
- const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
120
+ // There should always be an entry in the `cssMap` here.
129
121
  // The only valid scenario for a missing one is if someone had written
130
122
  // a file in their app using the .vanilla.js/.vanilla.css extension
131
-
132
123
  if (cssMap.has(absoluteId)) {
133
124
  // Keep the original query string for HMR.
134
125
  return absoluteId + (query ? `?${query}` : '');
135
126
  }
136
127
  },
137
-
138
128
  load(id) {
139
129
  const [validId] = id.split('?');
140
-
141
130
  if (!cssMap.has(validId)) {
142
131
  return;
143
132
  }
144
-
145
133
  const css = cssMap.get(validId);
146
-
147
134
  if (typeof css !== 'string') {
148
135
  return;
149
136
  }
150
-
151
137
  if (validId.endsWith(virtualExtCss)) {
152
138
  return css;
153
139
  }
154
-
155
140
  return outdent__default["default"]`
156
141
  import { injectStyles } from '@vanilla-extract/css/injectStyles';
157
142
 
@@ -171,24 +156,19 @@ function vanillaExtractPlugin({
171
156
  }
172
157
  `;
173
158
  },
174
-
175
159
  async transform(code, id, ssrParam) {
176
160
  const [validId] = id.split('?');
177
-
178
161
  if (!integration.cssFileFilter.test(validId)) {
179
162
  return null;
180
163
  }
181
-
182
164
  const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug';
183
165
  let ssr;
184
-
185
166
  if (typeof ssrParam === 'boolean') {
186
167
  ssr = ssrParam;
187
168
  } else {
188
169
  ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
189
170
  }
190
-
191
- if (ssr && !forceEmitCssInSsrBuild) {
171
+ if (ssr && !resolvedEmitCssInSsr) {
192
172
  return integration.transform({
193
173
  source: code,
194
174
  filePath: vite.normalizePath(validId),
@@ -197,7 +177,6 @@ function vanillaExtractPlugin({
197
177
  identOption
198
178
  });
199
179
  }
200
-
201
180
  const {
202
181
  source,
203
182
  watchFiles
@@ -207,7 +186,6 @@ function vanillaExtractPlugin({
207
186
  esbuildOptions,
208
187
  identOption
209
188
  });
210
-
211
189
  for (const file of watchFiles) {
212
190
  // In start mode, we need to prevent the file from rewatching itself.
213
191
  // If it's a `build --watch`, it needs to watch everything.
@@ -215,7 +193,6 @@ function vanillaExtractPlugin({
215
193
  this.addWatchFile(file);
216
194
  }
217
195
  }
218
-
219
196
  const output = await integration.processVanillaFile({
220
197
  source,
221
198
  filePath: validId,
@@ -224,40 +201,38 @@ function vanillaExtractPlugin({
224
201
  fileScope,
225
202
  source
226
203
  }) => {
227
- const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && forceEmitCssInSsrBuild ? virtualExtCss : virtualExtJs}`;
204
+ const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && resolvedEmitCssInSsr ? virtualExtCss : virtualExtJs}`;
228
205
  const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
229
206
  let cssSource = source;
230
-
231
207
  if (postCssConfig) {
232
- const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(source, { ...postCssConfig.options,
208
+ const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(source, {
209
+ ...postCssConfig.options,
233
210
  from: undefined,
234
211
  map: false
235
212
  });
236
213
  cssSource = postCssResult.css;
237
214
  }
238
-
239
215
  if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
240
216
  const {
241
217
  moduleGraph
242
218
  } = server;
243
219
  const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
244
-
245
220
  if (module) {
246
- moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
221
+ moduleGraph.invalidateModule(module);
247
222
 
223
+ // Vite uses this timestamp to add `?t=` query string automatically for HMR.
248
224
  module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
249
225
  }
250
-
251
226
  server.ws.send({
252
227
  type: 'custom',
253
228
  event: styleUpdateEvent(absoluteId),
254
229
  data: cssSource
255
230
  });
256
231
  }
232
+ cssMap.set(absoluteId, cssSource);
257
233
 
258
- cssMap.set(absoluteId, cssSource); // We use the root relative id here to ensure file contents (content-hashes)
234
+ // We use the root relative id here to ensure file contents (content-hashes)
259
235
  // are consistent across build machines
260
-
261
236
  return `import "${rootRelativeId}";`;
262
237
  }
263
238
  });
@@ -268,7 +243,6 @@ function vanillaExtractPlugin({
268
243
  }
269
244
  };
270
245
  }
271
-
272
246
  };
273
247
  }
274
248
 
@@ -7,13 +7,12 @@ import { getPackageInfo, cssFileFilter, transform, compile, processVanillaFile }
7
7
  // https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts
8
8
  const resolvePostcssConfig = async config => {
9
9
  var _config$css;
10
-
11
10
  // inline postcss config via vite config
12
11
  const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss;
13
12
  const inlineOptionsIsString = typeof inlineOptions === 'string';
14
-
15
13
  if (inlineOptions && !inlineOptionsIsString) {
16
- const options = { ...inlineOptions
14
+ const options = {
15
+ ...inlineOptions
17
16
  };
18
17
  delete options.plugins;
19
18
  return {
@@ -33,37 +32,33 @@ const resolvePostcssConfig = async config => {
33
32
  if (!/No PostCSS Config found/.test(e.message)) {
34
33
  throw e;
35
34
  }
36
-
37
35
  return null;
38
36
  }
39
37
  }
40
38
  };
41
39
 
42
40
  const styleUpdateEvent = fileId => `vanilla-extract-style-update:${fileId}`;
43
-
44
41
  const virtualExtCss = '.vanilla.css';
45
42
  const virtualExtJs = '.vanilla.js';
46
43
  function vanillaExtractPlugin({
47
44
  identifiers,
45
+ emitCssInSsr,
48
46
  esbuildOptions
49
47
  } = {}) {
50
48
  let config;
51
49
  let server;
52
50
  let postCssConfig;
53
51
  const cssMap = new Map();
54
- let forceEmitCssInSsrBuild = !!process.env.VITE_RSC_BUILD;
52
+ const hasEmitCssOverride = typeof emitCssInSsr === 'boolean';
53
+ let resolvedEmitCssInSsr = hasEmitCssOverride ? emitCssInSsr : !!process.env.VITE_RSC_BUILD;
55
54
  let packageName;
56
-
57
55
  const getAbsoluteVirtualFileId = source => normalizePath(path.join(config.root, source));
58
-
59
56
  return {
60
57
  name: 'vanilla-extract',
61
58
  enforce: 'pre',
62
-
63
59
  configureServer(_server) {
64
60
  server = _server;
65
61
  },
66
-
67
62
  config(_userConfig, env) {
68
63
  const include = env.command === 'serve' ? ['@vanilla-extract/css/injectStyles'] : [];
69
64
  return {
@@ -75,56 +70,46 @@ function vanillaExtractPlugin({
75
70
  }
76
71
  };
77
72
  },
78
-
79
73
  async configResolved(resolvedConfig) {
80
74
  config = resolvedConfig;
81
75
  packageName = getPackageInfo(config.root).name;
82
-
83
76
  if (config.command === 'serve') {
84
77
  postCssConfig = await resolvePostcssConfig(config);
85
78
  }
86
-
87
- if (config.plugins.some(plugin => ['astro:build', 'solid-start-server', 'vite-plugin-qwik'].includes(plugin.name))) {
88
- forceEmitCssInSsrBuild = true;
79
+ if (!hasEmitCssOverride && config.plugins.some(plugin => ['astro:build', 'solid-start-server', 'vite-plugin-qwik', 'vite-plugin-svelte'].includes(plugin.name))) {
80
+ resolvedEmitCssInSsr = true;
89
81
  }
90
82
  },
91
-
92
83
  resolveId(source) {
93
84
  const [validId, query] = source.split('?');
94
-
95
85
  if (!validId.endsWith(virtualExtCss) && !validId.endsWith(virtualExtJs)) {
96
86
  return;
97
- } // Absolute paths seem to occur often in monorepos, where files are
98
- // imported from outside the config root.
87
+ }
99
88
 
89
+ // Absolute paths seem to occur often in monorepos, where files are
90
+ // imported from outside the config root.
91
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
100
92
 
101
- const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId); // There should always be an entry in the `cssMap` here.
93
+ // There should always be an entry in the `cssMap` here.
102
94
  // The only valid scenario for a missing one is if someone had written
103
95
  // a file in their app using the .vanilla.js/.vanilla.css extension
104
-
105
96
  if (cssMap.has(absoluteId)) {
106
97
  // Keep the original query string for HMR.
107
98
  return absoluteId + (query ? `?${query}` : '');
108
99
  }
109
100
  },
110
-
111
101
  load(id) {
112
102
  const [validId] = id.split('?');
113
-
114
103
  if (!cssMap.has(validId)) {
115
104
  return;
116
105
  }
117
-
118
106
  const css = cssMap.get(validId);
119
-
120
107
  if (typeof css !== 'string') {
121
108
  return;
122
109
  }
123
-
124
110
  if (validId.endsWith(virtualExtCss)) {
125
111
  return css;
126
112
  }
127
-
128
113
  return outdent`
129
114
  import { injectStyles } from '@vanilla-extract/css/injectStyles';
130
115
 
@@ -144,24 +129,19 @@ function vanillaExtractPlugin({
144
129
  }
145
130
  `;
146
131
  },
147
-
148
132
  async transform(code, id, ssrParam) {
149
133
  const [validId] = id.split('?');
150
-
151
134
  if (!cssFileFilter.test(validId)) {
152
135
  return null;
153
136
  }
154
-
155
137
  const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug';
156
138
  let ssr;
157
-
158
139
  if (typeof ssrParam === 'boolean') {
159
140
  ssr = ssrParam;
160
141
  } else {
161
142
  ssr = ssrParam === null || ssrParam === void 0 ? void 0 : ssrParam.ssr;
162
143
  }
163
-
164
- if (ssr && !forceEmitCssInSsrBuild) {
144
+ if (ssr && !resolvedEmitCssInSsr) {
165
145
  return transform({
166
146
  source: code,
167
147
  filePath: normalizePath(validId),
@@ -170,7 +150,6 @@ function vanillaExtractPlugin({
170
150
  identOption
171
151
  });
172
152
  }
173
-
174
153
  const {
175
154
  source,
176
155
  watchFiles
@@ -180,7 +159,6 @@ function vanillaExtractPlugin({
180
159
  esbuildOptions,
181
160
  identOption
182
161
  });
183
-
184
162
  for (const file of watchFiles) {
185
163
  // In start mode, we need to prevent the file from rewatching itself.
186
164
  // If it's a `build --watch`, it needs to watch everything.
@@ -188,7 +166,6 @@ function vanillaExtractPlugin({
188
166
  this.addWatchFile(file);
189
167
  }
190
168
  }
191
-
192
169
  const output = await processVanillaFile({
193
170
  source,
194
171
  filePath: validId,
@@ -197,40 +174,38 @@ function vanillaExtractPlugin({
197
174
  fileScope,
198
175
  source
199
176
  }) => {
200
- const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && forceEmitCssInSsrBuild ? virtualExtCss : virtualExtJs}`;
177
+ const rootRelativeId = `${fileScope.filePath}${config.command === 'build' || ssr && resolvedEmitCssInSsr ? virtualExtCss : virtualExtJs}`;
201
178
  const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
202
179
  let cssSource = source;
203
-
204
180
  if (postCssConfig) {
205
- const postCssResult = await (await import('postcss')).default(postCssConfig.plugins).process(source, { ...postCssConfig.options,
181
+ const postCssResult = await (await import('postcss')).default(postCssConfig.plugins).process(source, {
182
+ ...postCssConfig.options,
206
183
  from: undefined,
207
184
  map: false
208
185
  });
209
186
  cssSource = postCssResult.css;
210
187
  }
211
-
212
188
  if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
213
189
  const {
214
190
  moduleGraph
215
191
  } = server;
216
192
  const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
217
-
218
193
  if (module) {
219
- moduleGraph.invalidateModule(module); // Vite uses this timestamp to add `?t=` query string automatically for HMR.
194
+ moduleGraph.invalidateModule(module);
220
195
 
196
+ // Vite uses this timestamp to add `?t=` query string automatically for HMR.
221
197
  module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
222
198
  }
223
-
224
199
  server.ws.send({
225
200
  type: 'custom',
226
201
  event: styleUpdateEvent(absoluteId),
227
202
  data: cssSource
228
203
  });
229
204
  }
205
+ cssMap.set(absoluteId, cssSource);
230
206
 
231
- cssMap.set(absoluteId, cssSource); // We use the root relative id here to ensure file contents (content-hashes)
207
+ // We use the root relative id here to ensure file contents (content-hashes)
232
208
  // are consistent across build machines
233
-
234
209
  return `import "${rootRelativeId}";`;
235
210
  }
236
211
  });
@@ -241,7 +216,6 @@ function vanillaExtractPlugin({
241
216
  }
242
217
  };
243
218
  }
244
-
245
219
  };
246
220
  }
247
221
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanilla-extract/vite-plugin",
3
- "version": "3.7.0",
3
+ "version": "3.8.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": "^6.0.1",
18
+ "@vanilla-extract/integration": "^6.0.2",
19
19
  "outdent": "^0.8.0",
20
20
  "postcss": "^8.3.6",
21
21
  "postcss-load-config": "^3.1.0"
@@ -24,6 +24,6 @@
24
24
  "vite": "^2.7.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "vite": "^2.2.3 || ^3.0.0"
27
+ "vite": "^2.2.3 || ^3.0.0 || ^4.0.3"
28
28
  }
29
29
  }