@vizejs/vite-plugin 0.667.0 → 0.668.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as vize } from "./plugin-BAahoMod.mjs";
1
+ import { t as vize } from "./plugin-tuM13VgA.mjs";
2
2
  import { u as rewriteStaticAssetUrls } from "./vue-version-BFh0eI6J.mjs";
3
3
  import { a as resolveViteConfigExport, i as resolveConfigExport, n as defineConfig, o as vizeConfigStore, r as loadConfig, t as VIZE_CONFIG_FILE_ENV } from "./config-LlMZcDZI.mjs";
4
4
  //#region src/index.ts
@@ -0,0 +1,2 @@
1
+ import { t as vize } from "./plugin-tuM13VgA.mjs";
2
+ export { vize };
@@ -401,8 +401,32 @@ function normalizeInlineStyleModifiers(id) {
401
401
  if (!params.has("vue") || params.get("type") !== "style" || params.getAll("type").length !== 1 || lastKey !== "vize-file" || params.getAll("vize-file").length !== 1 || !params.get("vize-file")?.endsWith(".vue")) return id;
402
402
  return `${id.slice(0, appended)}&inline&used`;
403
403
  }
404
+ /**
405
+ * A `<style src>` block's module: the src file itself, with a style query
406
+ * whose `vize-file` names the owning SFC (see createStyleImportUrl).
407
+ */
408
+ function isStyleSrcModuleId(id) {
409
+ const start = id.indexOf("?");
410
+ if (start < 0) return false;
411
+ const file = id.slice(0, start);
412
+ if (file.includes(STYLE_MARKER) || file.endsWith(".vue")) return false;
413
+ const params = new URLSearchParams(id.slice(start + 1));
414
+ return params.has("vue") && params.get("type") === "style" && params.has("vize-file");
415
+ }
416
+ /**
417
+ * The src file's own path for a `<style src>` module requested root-relative
418
+ * (a production import), relative to the root (Nuxt's inline style entries)
419
+ * or through `/@fs`.
420
+ */
421
+ function resolveStyleSrcModuleId(id, root) {
422
+ const start = id.indexOf("?");
423
+ let file = id.slice(0, start);
424
+ if (file.startsWith("/@fs/")) file = file.slice(4);
425
+ return `${(path.isAbsolute(file) && fs.existsSync(file) ? file : path.resolve(root, file.replace(/^\//, ""))).split(path.sep).join("/")}${id.slice(start)}`;
426
+ }
404
427
  /** Keep the CSS extension in the path, outside Vue/Nuxt's query metadata. */
405
428
  function createStyleVirtualId(id) {
429
+ if (isStyleSrcModuleId(id)) return id;
406
430
  id = normalizeInlineStyleModifiers(id);
407
431
  const start = id.indexOf("?");
408
432
  const filename = id.slice(0, start);
@@ -416,6 +440,7 @@ function createStyleVirtualId(id) {
416
440
  }
417
441
  /** Give Vite's CSS resolvers a physical origin without changing emitted imports. */
418
442
  function resolveStyleVirtualId(id, root) {
443
+ if (isStyleSrcModuleId(id)) return resolveStyleSrcModuleId(id, root);
419
444
  const styleId = createStyleVirtualId(id);
420
445
  const queryStart = styleId.indexOf("?");
421
446
  const marker = styleId.slice(0, queryStart).lastIndexOf(STYLE_MARKER);
@@ -435,7 +460,7 @@ function normalizeStyleVirtualId(id) {
435
460
  const params = new URLSearchParams(query);
436
461
  if (!params.has("vue")) return id;
437
462
  const source = params.get("vize-file");
438
- if (source && withoutPrefix.slice(0, start).includes(STYLE_MARKER)) return `${source}?${query}`;
463
+ if (source) return `${source}?${query}`;
439
464
  return withoutPrefix.replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
440
465
  }
441
466
  //#endregion
@@ -574,16 +599,23 @@ function isCssModule(block) {
574
599
  function needsCssPipeline(block) {
575
600
  return block.content.includes("@apply");
576
601
  }
577
- function createStyleImportUrl(filePath, params, root, isProduction) {
578
- let styleFilePath = filePath;
579
- if (isProduction && root) {
580
- const relativePath = path.relative(root, filePath);
581
- if (relativePath && relativePath !== ".." && !relativePath.startsWith(`..${path.sep}`) && !path.isAbsolute(relativePath)) {
582
- styleFilePath = `/${relativePath.split(path.sep).join("/")}`;
583
- params.set("vize-root-relative", "");
584
- }
585
- }
586
- return createStyleVirtualId(`${styleFilePath}?${params.toString()}`);
602
+ /** A production build names modules from the root, so they match across checkouts. */
603
+ function rootRelativePath(file, root, isProduction) {
604
+ if (!isProduction || !root) return null;
605
+ const relativePath = path.relative(root, file);
606
+ if (!relativePath || relativePath === ".." || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath)) return null;
607
+ return `/${relativePath.split(path.sep).join("/")}`;
608
+ }
609
+ function createStyleImportUrl(filePath, params, root, isProduction, block) {
610
+ const owner = rootRelativePath(filePath, root, isProduction);
611
+ if (owner) params.set("vize-root-relative", "");
612
+ const styleFilePath = owner ?? filePath;
613
+ if (!block.src) return createStyleVirtualId(`${styleFilePath}?${params.toString()}`);
614
+ // @vitejs/plugin-vue, so Vite resolves its relative `@import`, `@use` and
615
+ params.set("vize-file", styleFilePath);
616
+ const src = owner && rootRelativePath(block.src, root, isProduction) || block.src;
617
+ const lang = `${isCssModule(block) ? "module." : ""}${block.lang ?? "css"}`;
618
+ return `${src}?${params.toString().replaceAll(".", "%2E")}&lang.${lang}`;
587
619
  }
588
620
  /**
589
621
  * Check if any style blocks in the compiled module require delegation to
@@ -700,16 +732,16 @@ function generateOutputWithMap(compiled, options) {
700
732
  if (isCssModule(block)) throw new Error("<style module> is not supported in custom element mode");
701
733
  params.set("inline", "");
702
734
  const bindingName = `_style_${block.index}`;
703
- const importUrl = createStyleImportUrl(filePath, params, root, isProduction);
735
+ const importUrl = createStyleImportUrl(filePath, params, root, isProduction, block);
704
736
  styleImports.push(`import ${bindingName} from ${JSON.stringify(importUrl)};`);
705
737
  customElementStyleBindings.push(bindingName);
706
738
  } else if (isCssModule(block)) {
707
739
  const bindingName = typeof block.module === "string" ? block.module : "$style";
708
740
  params.set("module", typeof block.module === "string" ? block.module : "");
709
- const importUrl = createStyleImportUrl(filePath, params, root, isProduction);
741
+ const importUrl = createStyleImportUrl(filePath, params, root, isProduction, block);
710
742
  cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(importUrl)};`);
711
743
  } else {
712
- const importUrl = createStyleImportUrl(filePath, params, root, isProduction);
744
+ const importUrl = createStyleImportUrl(filePath, params, root, isProduction, block);
713
745
  styleImports.push(`import ${JSON.stringify(importUrl)};`);
714
746
  }
715
747
  }
@@ -1095,10 +1127,14 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
1095
1127
  ["template", parsed.template],
1096
1128
  ["script", parsed.script],
1097
1129
  ["script", parsed.scriptSetup],
1098
- ...parsed.styles.map((style) => ["style", style])
1130
+ ...parsed.styles.map((style, index) => [
1131
+ "style",
1132
+ style,
1133
+ index
1134
+ ])
1099
1135
  ];
1100
1136
  const found = [];
1101
- for (const [tag, block] of blocks) {
1137
+ for (const [tag, block, styleIndex] of blocks) {
1102
1138
  if (!block) continue;
1103
1139
  const { start, tagStart, tagEnd } = block.loc;
1104
1140
  const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
@@ -1106,7 +1142,8 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
1106
1142
  tag,
1107
1143
  ...split,
1108
1144
  tagStart,
1109
- tagEnd
1145
+ tagEnd,
1146
+ styleIndex
1110
1147
  });
1111
1148
  }
1112
1149
  return found;
@@ -1133,9 +1170,11 @@ function readSrcBlock(filePath, tag, src, resolutions) {
1133
1170
  * the bundler's `resolutions` (see {@link sfcSrcFile}).
1134
1171
  */
1135
1172
  function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
1173
+ const styleSrcs = /* @__PURE__ */ new Map();
1136
1174
  if (!SRC_BLOCK_HINT.test(source)) return {
1137
1175
  source,
1138
- dependencies: []
1176
+ dependencies: [],
1177
+ styleSrcs
1139
1178
  };
1140
1179
  const bytes = Buffer.from(source);
1141
1180
  const edits = [];
@@ -1143,6 +1182,7 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
1143
1182
  for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
1144
1183
  const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
1145
1184
  dependencies.push(file.path);
1185
+ if (block.styleIndex !== void 0) styleSrcs.set(block.styleIndex, file.path);
1146
1186
  edits.push({
1147
1187
  start: block.tagStart,
1148
1188
  end: block.tagEnd,
@@ -1151,7 +1191,8 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
1151
1191
  }
1152
1192
  if (edits.length === 0) return {
1153
1193
  source,
1154
- dependencies
1194
+ dependencies,
1195
+ styleSrcs
1155
1196
  };
1156
1197
  edits.sort((a, b) => a.start - b.start);
1157
1198
  const parts = [];
@@ -1163,7 +1204,8 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
1163
1204
  parts.push(bytes.subarray(offset));
1164
1205
  return {
1165
1206
  source: Buffer.concat(parts).toString("utf8"),
1166
- dependencies
1207
+ dependencies,
1208
+ styleSrcs
1167
1209
  };
1168
1210
  }
1169
1211
  //#endregion
@@ -1246,11 +1288,11 @@ var VizeSfcCompileError = class extends Error {
1246
1288
  function formatCompileErrorMessage(filePath, diagnostics) {
1247
1289
  return `[vize] Compilation failed in ${filePath}:\n${diagnostics.map((diagnostic) => ` - ${diagnostic}`).join("\n")}`;
1248
1290
  }
1249
- function normalizeStyleBlocks(styles) {
1291
+ function normalizeStyleBlocks(styles, styleSrcs) {
1250
1292
  if (!styles) return [];
1251
1293
  return styles.map((block) => ({
1252
1294
  content: block.content,
1253
- src: block.src ?? null,
1295
+ src: styleSrcs?.get(block.index) ?? block.src ?? null,
1254
1296
  lang: block.lang ?? null,
1255
1297
  scoped: block.scoped,
1256
1298
  module: block.module ? block.moduleName ?? true : false,
@@ -1276,7 +1318,7 @@ function compileFile(filePath, cache, options, source, diagnostics) {
1276
1318
  styleHash: result.styleHash,
1277
1319
  scriptHash: result.scriptHash,
1278
1320
  macroArtifacts: result.macroArtifacts ?? [],
1279
- styles: normalizeStyleBlocks(result.styles),
1321
+ styles: normalizeStyleBlocks(result.styles, resolved.styleSrcs),
1280
1322
  dependencies: [...resolved.dependencies, ...result.dependencies ?? []]
1281
1323
  };
1282
1324
  cache.set(filePath, compiled);
@@ -1321,9 +1363,11 @@ function compileJsxModule(filePath, source, options = {}) {
1321
1363
  */
1322
1364
  function compileBatch(files, cache, options) {
1323
1365
  const dependenciesByPath = /* @__PURE__ */ new Map();
1366
+ const styleSrcsByPath = /* @__PURE__ */ new Map();
1324
1367
  const resolvedFiles = files.map((file) => {
1325
1368
  const resolved = inlineSfcSrcBlocks(native.parseSfc, file.path, file.source, options.srcResolutions?.get(file.path));
1326
1369
  dependenciesByPath.set(file.path, resolved.dependencies);
1370
+ styleSrcsByPath.set(file.path, resolved.styleSrcs);
1327
1371
  return {
1328
1372
  path: file.path,
1329
1373
  source: resolved.source,
@@ -1360,7 +1404,7 @@ function compileBatch(files, cache, options) {
1360
1404
  styleHash: fileResult.styleHash,
1361
1405
  scriptHash: fileResult.scriptHash,
1362
1406
  macroArtifacts: fileResult.macroArtifacts ?? [],
1363
- styles: normalizeStyleBlocks(fileResult.styles),
1407
+ styles: normalizeStyleBlocks(fileResult.styles, styleSrcsByPath.get(fileResult.path)),
1364
1408
  dependencies: [...dependenciesByPath.get(fileResult.path) ?? [], ...fileResult.dependencies ?? []]
1365
1409
  });
1366
1410
  if (fileResult.errors.length > 0) console.error(formatCompileErrorMessage(fileResult.path, fileResult.errors));
@@ -2781,7 +2825,7 @@ function nativeCssAliasRules(state) {
2781
2825
  return state.cssAliasRules.length === 0 ? EMPTY_NATIVE_ALIAS_RULES : state.cssAliasRules.map(toNativeCssAliasRule);
2782
2826
  }
2783
2827
  function isPotentialVizeResolveId(id) {
2784
- return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || isProjectVueRuntimeRequest(id) || id === "virtual:vize-styles" || id.endsWith(".vue") || /\.vue(?:\?|\.__vize_style_)/.test(id) || /\.vue\.tsx?\?/.test(id) || id.includes("?macro=true") || id.includes("?definePage");
2828
+ return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || isProjectVueRuntimeRequest(id) || id === "virtual:vize-styles" || id.endsWith(".vue") || /\.vue(?:\?|\.__vize_style_)|vize-file=/.test(id) || /\.vue\.tsx?\?/.test(id) || id.includes("?macro=true") || id.includes("?definePage");
2785
2829
  }
2786
2830
  function classifyImporterRequest(importer) {
2787
2831
  return importer ? classifyVitePluginRequest(importer) : null;
@@ -3269,7 +3313,7 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
3269
3313
  } : null;
3270
3314
  }
3271
3315
  function loadHook(state, id, loadOptions) {
3272
- if (id !== "\0vize:all-styles.css" && !id.startsWith("\0") && !id.includes(".vue")) return null;
3316
+ if (id !== "\0vize:all-styles.css" && !id.startsWith("\0") && !id.includes(".vue") && !id.includes("vize-file=")) return null;
3273
3317
  const request = classifyVitePluginRequest(id);
3274
3318
  const pluginVisibleVirtualPath = fromPluginVisibleVirtualId(id);
3275
3319
  const loadableVueSfcPath = getLoadableVueSfcPath(request);
@@ -400,7 +400,7 @@ function defineConfig(config = {}, integration = {}) {
400
400
  const legacy = compiler !== false && (await import("./vue-version-DOjZaMiI.mjs")).isLegacyVueCompatibilityMode(compiler);
401
401
  const plugins = compiler === false || legacy ? [...vp.plugins ?? []] : await withoutVueCompiler(vp.plugins ?? []);
402
402
  if (compiler !== false) {
403
- const { vize } = await import("./plugin-CcTdAxZL.mjs");
403
+ const { vize } = await import("./plugin-CFfuvH8O.mjs");
404
404
  plugins.push(vize({
405
405
  ...plugin,
406
406
  configMode: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.667.0",
3
+ "version": "0.668.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -51,13 +51,13 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@vizejs/native": "0.667.0",
55
- "@vizejs/unplugin": "0.667.0",
54
+ "@vizejs/native": "0.668.0",
55
+ "@vizejs/unplugin": "0.668.0",
56
56
  "jsonc-parser": "^3.3.1",
57
57
  "oxc-parser": "0.144.0",
58
58
  "picomatch": "4.0.5",
59
59
  "tinyglobby": "0.2.17",
60
- "vize": "0.667.0"
60
+ "vize": "0.668.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.9.2",
@@ -1,2 +0,0 @@
1
- import { t as vize } from "./plugin-BAahoMod.mjs";
2
- export { vize };