@unocss/vite 66.5.9 → 66.5.10

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.
Files changed (2) hide show
  1. package/dist/index.mjs +42 -22
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -24,8 +24,6 @@ const VIRTUAL_ENTRY_ALIAS = [
24
24
  /^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
25
25
  ];
26
26
  const LAYER_MARK_ALL = "__ALL__";
27
- const RESOLVED_ID_WITH_QUERY_RE = /[/\\]__uno(_.*?)?\.css(\?.*)?$/;
28
- const RESOLVED_ID_RE = /[/\\]__uno(?:_(.*?))?\.css$/;
29
27
 
30
28
  const defaultPipelineExclude = [cssIdRE];
31
29
  const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|vine.ts|mdx?|astro|elm|php|phtml|marko|html)($|\?)/];
@@ -113,6 +111,22 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
113
111
  if (tasks[0] === _tasks[0])
114
112
  tasks.splice(0, _tasks.length);
115
113
  }
114
+ const vmpCache = /* @__PURE__ */ new Map();
115
+ async function getVMPRegexes() {
116
+ const config = await getConfig();
117
+ const prefix = config.virtualModulePrefix || "__uno";
118
+ if (vmpCache.has(prefix))
119
+ return vmpCache.get(prefix);
120
+ const RESOLVED_ID_WITH_QUERY_RE = new RegExp(`[/\\\\]${prefix}(_.*?)?\\.css(\\?.*)?$`);
121
+ const RESOLVED_ID_RE = new RegExp(`[/\\\\]${prefix}(?:_(.*?))?.css$`);
122
+ const regexes = {
123
+ prefix,
124
+ RESOLVED_ID_WITH_QUERY_RE,
125
+ RESOLVED_ID_RE
126
+ };
127
+ vmpCache.set(prefix, regexes);
128
+ return regexes;
129
+ }
116
130
  return {
117
131
  get ready() {
118
132
  return ready;
@@ -142,7 +156,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
142
156
  return root;
143
157
  },
144
158
  updateRoot,
145
- getConfigFileList: () => configFileList
159
+ getConfigFileList: () => configFileList,
160
+ getVMPRegexes
146
161
  };
147
162
  }
148
163
 
@@ -462,13 +477,15 @@ async function setupContentExtractor(ctx, shouldWatch = false) {
462
477
  }
463
478
  }
464
479
 
465
- function resolveId(id, importer) {
466
- if (id.match(RESOLVED_ID_WITH_QUERY_RE))
480
+ async function resolveId(ctx, id, importer) {
481
+ const { RESOLVED_ID_WITH_QUERY_RE, prefix } = await ctx.getVMPRegexes();
482
+ if (id.match(RESOLVED_ID_WITH_QUERY_RE)) {
467
483
  return id;
484
+ }
468
485
  for (const alias of VIRTUAL_ENTRY_ALIAS) {
469
486
  const match = id.match(alias);
470
487
  if (match) {
471
- let virtual = match[1] ? `__uno_${match[1]}.css` : "__uno.css";
488
+ let virtual = match[1] ? `${prefix}_${match[1]}.css` : `${prefix}.css`;
472
489
  virtual += match[2] || "";
473
490
  if (importer)
474
491
  virtual = resolve$1(importer, "..", virtual);
@@ -478,10 +495,12 @@ function resolveId(id, importer) {
478
495
  }
479
496
  }
480
497
  }
481
- function resolveLayer(id) {
498
+ async function resolveLayer(ctx, id) {
499
+ const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
482
500
  const match = id.match(RESOLVED_ID_RE);
483
- if (match)
501
+ if (match) {
484
502
  return match[1] || LAYER_MARK_ALL;
503
+ }
485
504
  }
486
505
  function getLayerPlaceholder(layer) {
487
506
  return `#--unocss--{layer:${layer};escape-view:\\"\\'\\\`\\\\}`;
@@ -557,10 +576,10 @@ function GlobalModeBuildPlugin(ctx) {
557
576
  tasks.push(extract(code, filename));
558
577
  }
559
578
  },
560
- resolveId(id, importer) {
561
- const entry = resolveId(id, importer);
579
+ async resolveId(id, importer) {
580
+ const entry = await resolveId(ctx, id, importer);
562
581
  if (entry) {
563
- const layer = resolveLayer(entry);
582
+ const layer = await resolveLayer(ctx, entry);
564
583
  if (layer) {
565
584
  if (importer)
566
585
  unocssImporters.add(importer);
@@ -574,8 +593,8 @@ function GlobalModeBuildPlugin(ctx) {
574
593
  return entry;
575
594
  }
576
595
  },
577
- load(id) {
578
- const layer = resolveLayer(getPath(id));
596
+ async load(id) {
597
+ const layer = await resolveLayer(ctx, getPath(id));
579
598
  if (layer) {
580
599
  if (!vfsLayers.has(layer)) {
581
600
  this.error(`[unocss] layer ${JSON.stringify(id)} is imported but not being resolved before, it might be an internal bug of UnoCSS`);
@@ -625,7 +644,8 @@ function GlobalModeBuildPlugin(ctx) {
625
644
  {
626
645
  name: "unocss:global:build:generate",
627
646
  apply: "build",
628
- async renderChunk(code, chunk, options) {
647
+ async renderChunk(_, chunk, options) {
648
+ const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
629
649
  const entryModules = Object.keys(chunk.modules).filter((id) => RESOLVED_ID_RE.test(id));
630
650
  if (!entryModules.length)
631
651
  return null;
@@ -696,7 +716,7 @@ function GlobalModeDevPlugin(ctx) {
696
716
  break;
697
717
  tokensSize = tokens.size;
698
718
  } while (true);
699
- const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries).map((i) => resolveLayer(i)).filter((i) => !!i)) : result.getLayer(layer);
719
+ const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i))).then((layers) => layers.filter((i) => !!i))) : result.getLayer(layer);
700
720
  const hash = getHash(css || "", HASH_LENGTH);
701
721
  lastServedHash.set(layer, hash);
702
722
  lastServedTime = Date.now();
@@ -797,8 +817,8 @@ function GlobalModeDevPlugin(ctx) {
797
817
  tasks.push(extract(code, filename));
798
818
  }
799
819
  },
800
- resolveId(id) {
801
- const entry = resolveId(id);
820
+ async resolveId(id) {
821
+ const entry = await resolveId(ctx, id);
802
822
  if (entry) {
803
823
  resolved = true;
804
824
  clearWarnTimer();
@@ -807,7 +827,7 @@ function GlobalModeDevPlugin(ctx) {
807
827
  }
808
828
  },
809
829
  async load(id) {
810
- const layer = resolveLayer(getPath(id));
830
+ const layer = await resolveLayer(ctx, getPath(id));
811
831
  if (!layer)
812
832
  return null;
813
833
  const { hash, css } = await generateCSS(layer);
@@ -828,7 +848,7 @@ function GlobalModeDevPlugin(ctx) {
828
848
  },
829
849
  enforce: "post",
830
850
  async transform(code, id) {
831
- const layer = resolveLayer(getPath(id));
851
+ const layer = await resolveLayer(ctx, getPath(id));
832
852
  if (layer && code.includes("import.meta.hot")) {
833
853
  let hmr = `
834
854
  try {
@@ -895,13 +915,13 @@ function PerModuleModePlugin(ctx) {
895
915
  {
896
916
  name: "unocss:module-scope:pre",
897
917
  enforce: "pre",
898
- resolveId(id) {
899
- const entry = resolveId(id);
918
+ async resolveId(id) {
919
+ const entry = await resolveId(ctx, id);
900
920
  if (entry)
901
921
  return entry;
902
922
  },
903
923
  async load(id) {
904
- const layer = resolveLayer(getPath(id));
924
+ const layer = await resolveLayer(ctx, getPath(id));
905
925
  if (!layer)
906
926
  return null;
907
927
  await ctx.ready;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
3
  "type": "module",
4
- "version": "66.5.9",
4
+ "version": "66.5.10",
5
5
  "description": "The Vite plugin for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -55,9 +55,9 @@
55
55
  "pathe": "^2.0.3",
56
56
  "tinyglobby": "^0.2.15",
57
57
  "unplugin-utils": "^0.3.1",
58
- "@unocss/config": "66.5.9",
59
- "@unocss/inspector": "66.5.9",
60
- "@unocss/core": "66.5.9"
58
+ "@unocss/config": "66.5.10",
59
+ "@unocss/inspector": "66.5.10",
60
+ "@unocss/core": "66.5.10"
61
61
  },
62
62
  "devDependencies": {
63
63
  "vite": "^7.2.2"