@unocss/vite 0.31.17 → 0.32.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/dist/index.cjs CHANGED
@@ -168,10 +168,27 @@ function ChunkModeBuildPlugin({ uno, filter }) {
168
168
  };
169
169
  }
170
170
 
171
- function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }) {
171
+ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
172
172
  const vfsLayerMap = /* @__PURE__ */ new Map();
173
173
  let tasks = [];
174
+ let cssPostPlugin;
174
175
  let cssPlugin;
176
+ async function transformCSS(css, id) {
177
+ const {
178
+ postcss = true
179
+ } = await getConfig();
180
+ if (!cssPlugin || !postcss)
181
+ return css;
182
+ const result = await cssPlugin.transform(css, id);
183
+ if (!result)
184
+ return css;
185
+ if (typeof result === "string")
186
+ css = result;
187
+ else if (result.code)
188
+ css = result.code;
189
+ css = css.replace(/[\n\r]/g, "");
190
+ return css;
191
+ }
175
192
  return [
176
193
  {
177
194
  name: "unocss:global:build:scan",
@@ -205,23 +222,25 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter })
205
222
  return getLayerPlaceholder(layer);
206
223
  },
207
224
  async configResolved(config) {
208
- cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
225
+ cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
226
+ cssPlugin = config.plugins.find((i) => i.name === "vite:css");
209
227
  await ready;
210
228
  },
211
229
  async renderChunk(_, chunk) {
212
- if (!cssPlugin)
230
+ if (!cssPostPlugin)
213
231
  return null;
214
232
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
215
233
  if (!chunks.length)
216
234
  return null;
217
235
  const tokens2 = /* @__PURE__ */ new Set();
218
236
  await Promise.all(chunks.map((c) => uno.applyExtractors(modules.get(c) || "", c, tokens2)));
219
- const { css } = await uno.generate(tokens2, { minify: true });
237
+ let { css } = await uno.generate(tokens2, { minify: true });
220
238
  if (!css)
221
239
  return null;
222
- const hash = getHash(css);
223
240
  const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
224
- await cssPlugin.transform(getHashPlaceholder(hash), fakeCssId);
241
+ css = await transformCSS(css, fakeCssId);
242
+ const hash = getHash(css);
243
+ await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
225
244
  chunk.modules[fakeCssId] = {
226
245
  code: null,
227
246
  originalLength: 0,
@@ -249,10 +268,11 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter })
249
268
  for (const file of cssFiles) {
250
269
  const chunk = bundle[file];
251
270
  if (chunk.type === "asset" && typeof chunk.source === "string") {
252
- chunk.source = chunk.source.replace(HASH_PLACEHOLDER_RE, "").replace(LAYER_PLACEHOLDER_RE, (_2, __, layer) => {
271
+ const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "").replace(LAYER_PLACEHOLDER_RE, (_2, __, layer) => {
253
272
  replaced = true;
254
273
  return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "";
255
274
  });
275
+ chunk.source = await transformCSS(css, `${chunk.fileName}.css`);
256
276
  }
257
277
  }
258
278
  if (!replaced)
package/dist/index.d.ts CHANGED
@@ -29,13 +29,19 @@ interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
29
29
  * @default false
30
30
  */
31
31
  transformCSS?: boolean | 'pre' | 'post';
32
+ /**
33
+ *
34
+ * make the generate css processed by postcss(https://vitejs.dev/guide/features.html#postcss)
35
+ * @default true
36
+ */
37
+ postcss?: boolean;
32
38
  }
33
39
 
34
40
  declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plugin;
35
41
 
36
42
  declare function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }: UnocssPluginContext): Plugin[];
37
43
 
38
- declare function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }: UnocssPluginContext): Plugin[];
44
+ declare function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }: UnocssPluginContext<VitePluginConfig>): Plugin[];
39
45
 
40
46
  declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin[];
41
47
 
package/dist/index.mjs CHANGED
@@ -158,10 +158,27 @@ function ChunkModeBuildPlugin({ uno, filter }) {
158
158
  };
159
159
  }
160
160
 
161
- function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }) {
161
+ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
162
162
  const vfsLayerMap = /* @__PURE__ */ new Map();
163
163
  let tasks = [];
164
+ let cssPostPlugin;
164
165
  let cssPlugin;
166
+ async function transformCSS(css, id) {
167
+ const {
168
+ postcss = true
169
+ } = await getConfig();
170
+ if (!cssPlugin || !postcss)
171
+ return css;
172
+ const result = await cssPlugin.transform(css, id);
173
+ if (!result)
174
+ return css;
175
+ if (typeof result === "string")
176
+ css = result;
177
+ else if (result.code)
178
+ css = result.code;
179
+ css = css.replace(/[\n\r]/g, "");
180
+ return css;
181
+ }
165
182
  return [
166
183
  {
167
184
  name: "unocss:global:build:scan",
@@ -195,23 +212,25 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter })
195
212
  return getLayerPlaceholder(layer);
196
213
  },
197
214
  async configResolved(config) {
198
- cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
215
+ cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
216
+ cssPlugin = config.plugins.find((i) => i.name === "vite:css");
199
217
  await ready;
200
218
  },
201
219
  async renderChunk(_, chunk) {
202
- if (!cssPlugin)
220
+ if (!cssPostPlugin)
203
221
  return null;
204
222
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
205
223
  if (!chunks.length)
206
224
  return null;
207
225
  const tokens2 = /* @__PURE__ */ new Set();
208
226
  await Promise.all(chunks.map((c) => uno.applyExtractors(modules.get(c) || "", c, tokens2)));
209
- const { css } = await uno.generate(tokens2, { minify: true });
227
+ let { css } = await uno.generate(tokens2, { minify: true });
210
228
  if (!css)
211
229
  return null;
212
- const hash = getHash(css);
213
230
  const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
214
- await cssPlugin.transform(getHashPlaceholder(hash), fakeCssId);
231
+ css = await transformCSS(css, fakeCssId);
232
+ const hash = getHash(css);
233
+ await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
215
234
  chunk.modules[fakeCssId] = {
216
235
  code: null,
217
236
  originalLength: 0,
@@ -239,10 +258,11 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter })
239
258
  for (const file of cssFiles) {
240
259
  const chunk = bundle[file];
241
260
  if (chunk.type === "asset" && typeof chunk.source === "string") {
242
- chunk.source = chunk.source.replace(HASH_PLACEHOLDER_RE, "").replace(LAYER_PLACEHOLDER_RE, (_2, __, layer) => {
261
+ const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "").replace(LAYER_PLACEHOLDER_RE, (_2, __, layer) => {
243
262
  replaced = true;
244
263
  return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "";
245
264
  });
265
+ chunk.source = await transformCSS(css, `${chunk.fileName}.css`);
246
266
  }
247
267
  }
248
268
  if (!replaced)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.31.17",
3
+ "version": "0.32.0",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -43,11 +43,11 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.31.17",
47
- "@unocss/core": "0.31.17",
48
- "@unocss/inspector": "0.31.17",
49
- "@unocss/scope": "0.31.17",
50
- "@unocss/transformer-directives": "0.31.17",
46
+ "@unocss/config": "0.32.0",
47
+ "@unocss/core": "0.32.0",
48
+ "@unocss/inspector": "0.32.0",
49
+ "@unocss/scope": "0.32.0",
50
+ "@unocss/transformer-directives": "0.32.0",
51
51
  "magic-string": "^0.26.1"
52
52
  },
53
53
  "devDependencies": {