@unocss/vite 0.37.3 → 0.38.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/dist/index.cjs CHANGED
@@ -73,6 +73,15 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
73
73
  tokens.clear();
74
74
  await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
75
75
  invalidate();
76
+ const presets = /* @__PURE__ */ new Set();
77
+ uno.config.presets.forEach((i) => {
78
+ if (!i.name)
79
+ return;
80
+ if (presets.has(i.name))
81
+ console.warn(`[unocss] duplication of preset ${i.name} found, there might be something wrong with your config.`);
82
+ else
83
+ presets.add(i.name);
84
+ });
76
85
  return result;
77
86
  }
78
87
  async function updateRoot(newRoot) {
@@ -197,15 +206,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
197
206
  const vfsLayerMap = /* @__PURE__ */ new Map();
198
207
  const layerImporterMap = /* @__PURE__ */ new Map();
199
208
  let tasks = [];
200
- let cssPostPlugin;
201
- let cssPlugin;
202
- async function transformCSS(css, id) {
209
+ const cssPostPlugins = /* @__PURE__ */ new Map();
210
+ const cssPlugins = /* @__PURE__ */ new Map();
211
+ async function transformCSS(css, id, dir) {
203
212
  const {
204
213
  postcss = true
205
214
  } = await getConfig();
206
- if (!cssPlugin || !postcss)
215
+ if (!cssPlugins.get(dir) || !postcss)
207
216
  return css;
208
- const result = await cssPlugin.transform(css, id);
217
+ const result = await cssPlugins.get(dir).transform(css, id);
209
218
  if (!result)
210
219
  return css;
211
220
  if (typeof result === "string")
@@ -258,12 +267,12 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
258
267
  }
259
268
  },
260
269
  async configResolved(config) {
261
- cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
262
- cssPlugin = config.plugins.find((i) => i.name === "vite:css");
270
+ cssPostPlugins.set(config.build.outDir, config.plugins.find((i) => i.name === "vite:css-post"));
271
+ cssPlugins.set(config.build.outDir, config.plugins.find((i) => i.name === "vite:css"));
263
272
  await ready;
264
273
  },
265
- async renderChunk(_, chunk) {
266
- if (!cssPostPlugin)
274
+ async renderChunk(_, chunk, options) {
275
+ if (!cssPostPlugins.get(options.dir))
267
276
  return null;
268
277
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
269
278
  if (!chunks.length)
@@ -276,9 +285,9 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
276
285
  return null;
277
286
  if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
278
287
  return null;
279
- css = await transformCSS(css, fakeCssId);
288
+ css = await transformCSS(css, fakeCssId, options.dir);
280
289
  const hash = getHash(css);
281
- await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
290
+ await cssPostPlugins.get(options.dir).transform(getHashPlaceholder(hash), fakeCssId);
282
291
  chunk.modules[fakeCssId] = {
283
292
  code: null,
284
293
  originalLength: 0,
@@ -295,7 +304,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
295
304
  return command === "build" && !options.build?.ssr;
296
305
  },
297
306
  enforce: "post",
298
- async generateBundle(_, bundle) {
307
+ async generateBundle(options, bundle) {
299
308
  const files = Object.keys(bundle);
300
309
  const cssFiles = files.filter((i) => i.endsWith(".css"));
301
310
  if (!cssFiles.length)
@@ -312,9 +321,9 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
312
321
  const chunk = bundle[file];
313
322
  if (chunk.type === "asset" && typeof chunk.source === "string") {
314
323
  const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
315
- chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_2, __, layer) => {
324
+ chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
316
325
  replaced = true;
317
- return await transformCSS(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "", `${chunk.fileName}.css`);
326
+ return await transformCSS(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "", `${chunk.fileName}.css`, options.dir);
318
327
  });
319
328
  }
320
329
  }
package/dist/index.mjs CHANGED
@@ -63,6 +63,15 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
63
63
  tokens.clear();
64
64
  await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
65
65
  invalidate();
66
+ const presets = /* @__PURE__ */ new Set();
67
+ uno.config.presets.forEach((i) => {
68
+ if (!i.name)
69
+ return;
70
+ if (presets.has(i.name))
71
+ console.warn(`[unocss] duplication of preset ${i.name} found, there might be something wrong with your config.`);
72
+ else
73
+ presets.add(i.name);
74
+ });
66
75
  return result;
67
76
  }
68
77
  async function updateRoot(newRoot) {
@@ -187,15 +196,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
187
196
  const vfsLayerMap = /* @__PURE__ */ new Map();
188
197
  const layerImporterMap = /* @__PURE__ */ new Map();
189
198
  let tasks = [];
190
- let cssPostPlugin;
191
- let cssPlugin;
192
- async function transformCSS(css, id) {
199
+ const cssPostPlugins = /* @__PURE__ */ new Map();
200
+ const cssPlugins = /* @__PURE__ */ new Map();
201
+ async function transformCSS(css, id, dir) {
193
202
  const {
194
203
  postcss = true
195
204
  } = await getConfig();
196
- if (!cssPlugin || !postcss)
205
+ if (!cssPlugins.get(dir) || !postcss)
197
206
  return css;
198
- const result = await cssPlugin.transform(css, id);
207
+ const result = await cssPlugins.get(dir).transform(css, id);
199
208
  if (!result)
200
209
  return css;
201
210
  if (typeof result === "string")
@@ -248,12 +257,12 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
248
257
  }
249
258
  },
250
259
  async configResolved(config) {
251
- cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
252
- cssPlugin = config.plugins.find((i) => i.name === "vite:css");
260
+ cssPostPlugins.set(config.build.outDir, config.plugins.find((i) => i.name === "vite:css-post"));
261
+ cssPlugins.set(config.build.outDir, config.plugins.find((i) => i.name === "vite:css"));
253
262
  await ready;
254
263
  },
255
- async renderChunk(_, chunk) {
256
- if (!cssPostPlugin)
264
+ async renderChunk(_, chunk, options) {
265
+ if (!cssPostPlugins.get(options.dir))
257
266
  return null;
258
267
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
259
268
  if (!chunks.length)
@@ -266,9 +275,9 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
266
275
  return null;
267
276
  if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
268
277
  return null;
269
- css = await transformCSS(css, fakeCssId);
278
+ css = await transformCSS(css, fakeCssId, options.dir);
270
279
  const hash = getHash(css);
271
- await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
280
+ await cssPostPlugins.get(options.dir).transform(getHashPlaceholder(hash), fakeCssId);
272
281
  chunk.modules[fakeCssId] = {
273
282
  code: null,
274
283
  originalLength: 0,
@@ -285,7 +294,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
285
294
  return command === "build" && !options.build?.ssr;
286
295
  },
287
296
  enforce: "post",
288
- async generateBundle(_, bundle) {
297
+ async generateBundle(options, bundle) {
289
298
  const files = Object.keys(bundle);
290
299
  const cssFiles = files.filter((i) => i.endsWith(".css"));
291
300
  if (!cssFiles.length)
@@ -302,9 +311,9 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
302
311
  const chunk = bundle[file];
303
312
  if (chunk.type === "asset" && typeof chunk.source === "string") {
304
313
  const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
305
- chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_2, __, layer) => {
314
+ chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
306
315
  replaced = true;
307
- return await transformCSS(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "", `${chunk.fileName}.css`);
316
+ return await transformCSS(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "", `${chunk.fileName}.css`, options.dir);
308
317
  });
309
318
  }
310
319
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.37.3",
3
+ "version": "0.38.1",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -43,15 +43,15 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.37.3",
47
- "@unocss/core": "0.37.3",
48
- "@unocss/inspector": "0.37.3",
49
- "@unocss/scope": "0.37.3",
50
- "@unocss/transformer-directives": "0.37.3",
46
+ "@unocss/config": "0.38.1",
47
+ "@unocss/core": "0.38.1",
48
+ "@unocss/inspector": "0.38.1",
49
+ "@unocss/scope": "0.38.1",
50
+ "@unocss/transformer-directives": "0.38.1",
51
51
  "magic-string": "^0.26.2"
52
52
  },
53
53
  "devDependencies": {
54
- "@unocss/shared-integration": "0.37.3",
54
+ "@unocss/shared-integration": "0.38.1",
55
55
  "vite": "^2.9.9"
56
56
  },
57
57
  "scripts": {