@vizejs/vite-plugin 0.345.0 → 0.350.2

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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as VizeVueVersion, c as VizeInspectorLintPlanRequest, d as LoadConfigOptions, f as ResolvedVizeConfig, i as VizeOptions, l as VizeInspectorOptions, m as VizeConfig, n as MacroArtifact, o as VizeVueFeatures, p as UserConfigExport, r as VizeCompatibilityOptions, s as VizeInspectorLintPlanProvider, t as CompiledModule, u as ConfigEnv } from "./types-T_Fu8G5I.mjs";
1
+ import { a as VizeInspectorLintPlanProvider, c as VizeCompatibilityOptions, d as LoadConfigOptions, f as ResolvedVizeConfig, i as VizeVueFeatures, l as VizeVueVersion, m as VizeConfig, n as CompiledModule, o as VizeInspectorLintPlanRequest, p as UserConfigExport, r as MacroArtifact, s as VizeInspectorOptions, t as VizeOptions, u as ConfigEnv } from "./types-0tlI4YFk.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/virtual.d.ts
package/dist/index.mjs CHANGED
@@ -448,6 +448,13 @@ function isCssModule(block) {
448
448
  function needsCssPipeline(block) {
449
449
  return block.content.includes("@apply");
450
450
  }
451
+ function styleVirtualSuffix(block) {
452
+ const lang = block.lang ?? "css";
453
+ return block.module !== false ? `.module.${lang}` : `.${lang}`;
454
+ }
455
+ function createStyleImportUrl(filePath, params, block) {
456
+ return `${filePath}?${params.toString()}${styleVirtualSuffix(block)}`;
457
+ }
451
458
  /**
452
459
  * Check if any style blocks in the compiled module require delegation to
453
460
  * Vite's CSS pipeline (preprocessor, CSS Modules, or PostCSS transforms).
@@ -505,7 +512,7 @@ function generateScopeId(filename) {
505
512
  * emitted as imports and `compiled.css` is not used.
506
513
  */
507
514
  function usesStyleImports(compiled, options) {
508
- return !!options.filePath && !!compiled.styles?.length && (hasDelegatedStyles(compiled) || !options.ssr && options.isProduction && !!options.extractCss);
515
+ return !!options.filePath && !!compiled.styles?.length && (options.customElement || hasDelegatedStyles(compiled) || !options.ssr && options.isProduction && !!options.extractCss);
509
516
  }
510
517
  /**
511
518
  * Whether `generateOutput` will embed `compiled.css` in the module.
@@ -524,7 +531,7 @@ function usesStyleImports(compiled, options) {
524
531
  * 300-file bench corpus).
525
532
  */
526
533
  function embedsInlineCss(compiled, options) {
527
- return !usesStyleImports(compiled, options) && !options.ssr && !!compiled.css && !(options.isProduction && !!options.extractCss);
534
+ return !usesStyleImports(compiled, options) && !options.customElement && !options.ssr && !!compiled.css && !(options.isProduction && !!options.extractCss);
528
535
  }
529
536
  function generateOutput(compiled, options) {
530
537
  return generateOutputWithMap(compiled, options).code;
@@ -538,7 +545,7 @@ function generateOutput(compiled, options) {
538
545
  * `null` when the compiler produced none.
539
546
  */
540
547
  function generateOutputWithMap(compiled, options) {
541
- const { isProduction, isDev, ssr, hmrUpdateType, extractCss, filePath } = options;
548
+ const { customElement, isProduction, isDev, ssr, hmrUpdateType, extractCss, filePath } = options;
542
549
  const emitted = new MappedModule(compiled.code, parseSourceMap(compiled.map));
543
550
  const moduleInfo = compiled.moduleShape ?? analyzeModuleOutput(emitted.code);
544
551
  const hasExportDefault = moduleInfo.hasDefaultExport;
@@ -565,6 +572,7 @@ function generateOutputWithMap(compiled, options) {
565
572
  if (usesStyleImports(compiled, options)) {
566
573
  const styleImports = [];
567
574
  const cssModuleImports = [];
575
+ const customElementStyleBindings = [];
568
576
  for (const block of compiled.styles) {
569
577
  const lang = block.lang ?? "css";
570
578
  const params = new URLSearchParams();
@@ -573,19 +581,27 @@ function generateOutputWithMap(compiled, options) {
573
581
  params.set("index", String(block.index));
574
582
  if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
575
583
  params.set("lang", lang);
576
- if (isCssModule(block)) {
584
+ if (customElement) {
585
+ if (isCssModule(block)) throw new Error("<style module> is not supported in custom element mode");
586
+ params.set("inline", "");
587
+ const bindingName = `_style_${block.index}`;
588
+ const importUrl = createStyleImportUrl(filePath, params, block);
589
+ styleImports.push(`import ${bindingName} from ${JSON.stringify(importUrl)};`);
590
+ customElementStyleBindings.push(bindingName);
591
+ } else if (isCssModule(block)) {
577
592
  const bindingName = typeof block.module === "string" ? block.module : "$style";
578
593
  params.set("module", typeof block.module === "string" ? block.module : "");
579
- const importUrl = `${filePath}?${params.toString()}`;
594
+ const importUrl = createStyleImportUrl(filePath, params, block);
580
595
  cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(importUrl)};`);
581
596
  } else {
582
- const importUrl = `${filePath}?${params.toString()}`;
597
+ const importUrl = createStyleImportUrl(filePath, params, block);
583
598
  styleImports.push(`import ${JSON.stringify(importUrl)};`);
584
599
  }
585
600
  }
586
601
  const allImports = [...styleImports, ...cssModuleImports].join("\n");
587
602
  if (allImports) emitted.edit(insertAfterStaticImports(emitted.code, allImports));
588
- if (cssModuleImports.length > 0) {
603
+ if (customElementStyleBindings.length > 0) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, `_sfc_main.styles = [${customElementStyleBindings.join(", ")}];`, { normalizeSemicolon: true }));
604
+ else if (cssModuleImports.length > 0) {
589
605
  const moduleBindings = [];
590
606
  for (const block of compiled.styles) if (isCssModule(block)) {
591
607
  const bindingName = typeof block.module === "string" ? block.module : "$style";
@@ -725,6 +741,37 @@ function createLogger(debug) {
725
741
  };
726
742
  }
727
743
  //#endregion
744
+ //#region src/plugin/plugin-vue-options.ts
745
+ const PLUGIN_VUE_COMPAT_VERSION = "6.0.7";
746
+ const DEFAULT_CUSTOM_ELEMENT_PATTERN = /\.ce\.vue$/;
747
+ function booleanCompilerOption(value) {
748
+ return typeof value === "boolean" ? value : void 0;
749
+ }
750
+ function resolvePluginVueCompileOptions(options) {
751
+ const compilerOptions = options.template?.compilerOptions;
752
+ const resolved = { styleTrim: options.style?.trim ?? true };
753
+ const templateCacheHandlers = booleanCompilerOption(compilerOptions?.cacheHandlers);
754
+ const templateComments = booleanCompilerOption(compilerOptions?.comments);
755
+ const templateHoistStatic = booleanCompilerOption(compilerOptions?.hoistStatic);
756
+ const templatePrefixIdentifiers = booleanCompilerOption(compilerOptions?.prefixIdentifiers);
757
+ if (templateCacheHandlers !== void 0) resolved.templateCacheHandlers = templateCacheHandlers;
758
+ if (templateComments !== void 0) resolved.templateComments = templateComments;
759
+ if (templateHoistStatic !== void 0) resolved.templateHoistStatic = templateHoistStatic;
760
+ if (templatePrefixIdentifiers !== void 0) resolved.templatePrefixIdentifiers = templatePrefixIdentifiers;
761
+ return resolved;
762
+ }
763
+ function resolveCustomElementOption(options) {
764
+ const featureCustomElement = options.features?.customElement;
765
+ if (featureCustomElement) return featureCustomElement;
766
+ if (options.customElement !== void 0) return options.customElement;
767
+ return DEFAULT_CUSTOM_ELEMENT_PATTERN;
768
+ }
769
+ function isPluginVueCustomElement(options, filePath) {
770
+ const customElement = resolveCustomElementOption(options);
771
+ if (typeof customElement === "boolean") return customElement;
772
+ return createFilter(customElement, void 0)(filePath);
773
+ }
774
+ //#endregion
728
775
  //#region src/plugin/precompile.ts
729
776
  const DEFAULT_PRECOMPILE_IGNORE_PATTERNS = [
730
777
  "node_modules/**",
@@ -770,8 +817,10 @@ function getCompileOptionsForRequest(state, ssr) {
770
817
  ssr,
771
818
  vapor: !ssr && (state.mergedOptions?.vapor ?? false),
772
819
  customRenderer: state.mergedOptions?.customRenderer ?? false,
773
- templateSyntax: state.mergedOptions?.templateSyntax ?? "standard"
820
+ templateSyntax: state.mergedOptions?.templateSyntax ?? "standard",
821
+ ...resolvePluginVueCompileOptions(state.mergedOptions ?? {})
774
822
  };
823
+ if (state.mergedOptions?.customElements !== void 0) options.customElements = state.mergedOptions.customElements;
775
824
  if (state.mergedOptions?.mode !== void 0) options.mode = state.mergedOptions.mode;
776
825
  if (state.mergedOptions?.runtimeModuleName !== void 0) options.runtimeModuleName = state.mergedOptions.runtimeModuleName;
777
826
  if (state.mergedOptions?.runtimeGlobalName !== void 0) options.runtimeGlobalName = state.mergedOptions.runtimeGlobalName;
@@ -826,6 +875,7 @@ function clearBuildCaches(state) {
826
875
  */
827
876
  var CompiledModuleCache = class extends Map {
828
877
  #ownersByDependency = /* @__PURE__ */ new Map();
878
+ #dependenciesByOwner = /* @__PURE__ */ new Map();
829
879
  /**
830
880
  * Deliberately takes no entries: `Map`'s constructor would call the
831
881
  * overridden `set` from inside `super()`, before `#ownersByDependency` exists.
@@ -836,12 +886,15 @@ var CompiledModuleCache = class extends Map {
836
886
  set(file, compiled) {
837
887
  this.#unindex(file);
838
888
  super.set(file, compiled);
889
+ const dependencies = /* @__PURE__ */ new Set();
839
890
  for (const dependency of compiled.dependencies ?? []) {
840
891
  const key = path.resolve(dependency);
892
+ dependencies.add(key);
841
893
  const owners = this.#ownersByDependency.get(key);
842
894
  if (owners) owners.add(file);
843
895
  else this.#ownersByDependency.set(key, new Set([file]));
844
896
  }
897
+ this.#dependenciesByOwner.set(file, dependencies);
845
898
  return this;
846
899
  }
847
900
  delete(file) {
@@ -850,24 +903,40 @@ var CompiledModuleCache = class extends Map {
850
903
  }
851
904
  clear() {
852
905
  this.#ownersByDependency.clear();
906
+ this.#dependenciesByOwner.clear();
853
907
  super.clear();
854
908
  }
909
+ /**
910
+ * Evict a compiled value while retaining the dependency ownership that is
911
+ * required to route another hot update before Vite reloads the owner module.
912
+ * The next `set` reconciles that retained snapshot with the new compilation.
913
+ */
914
+ evict(file) {
915
+ return super.delete(file);
916
+ }
855
917
  /** The cached SFCs that `src`-import `resolvedDependency`. */
856
918
  ownersOf(resolvedDependency) {
857
919
  const owners = this.#ownersByDependency.get(resolvedDependency);
858
920
  return owners ? [...owners] : [];
859
921
  }
860
922
  #unindex(file) {
861
- for (const dependency of super.get(file)?.dependencies ?? []) {
862
- const key = path.resolve(dependency);
863
- const owners = this.#ownersByDependency.get(key);
923
+ for (const dependency of this.#dependenciesByOwner.get(file) ?? []) {
924
+ const owners = this.#ownersByDependency.get(dependency);
864
925
  if (!owners) continue;
865
926
  owners.delete(file);
866
- if (owners.size === 0) this.#ownersByDependency.delete(key);
927
+ if (owners.size === 0) this.#ownersByDependency.delete(dependency);
867
928
  }
929
+ this.#dependenciesByOwner.delete(file);
868
930
  }
869
931
  };
870
932
  /**
933
+ * Invalidate a compiled module without dropping its HMR dependency routing.
934
+ * Hand-built plain Maps retain their historical delete behaviour.
935
+ */
936
+ function evictCompiledModule(cache, file) {
937
+ return cache instanceof CompiledModuleCache ? cache.evict(file) : cache.delete(file);
938
+ }
939
+ /**
871
940
  * Owners of `resolvedDependency` in one cache.
872
941
  *
873
942
  * Plain `Map`s — the hand-built states in unit tests — keep the original linear
@@ -888,10 +957,16 @@ function buildCompileFileOptions(filePath, options) {
888
957
  ssr: options.ssr,
889
958
  vapor: options.vapor,
890
959
  customRenderer: options.customRenderer ?? false,
960
+ ...options.customElements === void 0 ? {} : { customElements: options.customElements },
891
961
  experimentalInTagComments: options.experimentalInTagComments ?? false,
892
962
  experimentalPatternedTemplate: options.experimentalPatternedTemplate ?? false,
893
963
  experimentalServerScript: options.experimentalServerScript ?? false,
894
964
  scopeId: `data-v-${generateScopeId(filePath)}`,
965
+ styleTrim: options.styleTrim,
966
+ ...options.templateCacheHandlers === void 0 ? {} : { templateCacheHandlers: options.templateCacheHandlers },
967
+ ...options.templateComments === void 0 ? {} : { templateComments: options.templateComments },
968
+ ...options.templateHoistStatic === void 0 ? {} : { templateHoistStatic: options.templateHoistStatic },
969
+ ...options.templatePrefixIdentifiers === void 0 ? {} : { templatePrefixIdentifiers: options.templatePrefixIdentifiers },
895
970
  ...options.mode === void 0 ? {} : { mode: options.mode },
896
971
  ...options.templateSyntax === void 0 ? {} : { templateSyntax: options.templateSyntax },
897
972
  ...options.runtimeModuleName === void 0 ? {} : { runtimeModuleName: options.runtimeModuleName },
@@ -904,6 +979,7 @@ function buildCompileBatchOptions(options) {
904
979
  ssr: options.ssr,
905
980
  vapor: options.vapor,
906
981
  customRenderer: options.customRenderer ?? false,
982
+ ...options.customElements === void 0 ? {} : { customElements: options.customElements },
907
983
  experimentalInTagComments: options.experimentalInTagComments ?? false,
908
984
  experimentalPatternedTemplate: options.experimentalPatternedTemplate ?? false,
909
985
  experimentalServerScript: options.experimentalServerScript ?? false,
@@ -911,6 +987,11 @@ function buildCompileBatchOptions(options) {
911
987
  includeMacroArtifacts: true,
912
988
  includeHashes: true,
913
989
  includeSourceMap: options.sourceMap,
990
+ styleTrim: options.styleTrim,
991
+ ...options.templateCacheHandlers === void 0 ? {} : { templateCacheHandlers: options.templateCacheHandlers },
992
+ ...options.templateComments === void 0 ? {} : { templateComments: options.templateComments },
993
+ ...options.templateHoistStatic === void 0 ? {} : { templateHoistStatic: options.templateHoistStatic },
994
+ ...options.templatePrefixIdentifiers === void 0 ? {} : { templatePrefixIdentifiers: options.templatePrefixIdentifiers },
914
995
  ...options.mode === void 0 ? {} : { mode: options.mode },
915
996
  ...options.templateSyntax === void 0 ? {} : { templateSyntax: options.templateSyntax },
916
997
  ...options.runtimeModuleName === void 0 ? {} : { runtimeModuleName: options.runtimeModuleName },
@@ -1568,19 +1649,26 @@ function writeManifest(file, container, onDiagnostic) {
1568
1649
  * that reaches the native compiler reaches the key with it.
1569
1650
  */
1570
1651
  function resolvePrecompileBatchOptions(state) {
1652
+ const requestOptions = getCompileOptionsForRequest(state, false);
1571
1653
  return {
1572
- sourceMap: getCompileOptionsForRequest(state, false).sourceMap,
1654
+ sourceMap: requestOptions.sourceMap,
1573
1655
  ssr: false,
1574
1656
  vapor: state.mergedOptions.vapor ?? false,
1575
1657
  mode: state.mergedOptions.mode,
1576
1658
  customRenderer: state.mergedOptions.customRenderer ?? false,
1659
+ customElements: state.mergedOptions.customElements,
1577
1660
  templateSyntax: state.mergedOptions.templateSyntax ?? "standard",
1578
1661
  experimentalInTagComments: state.mergedOptions.experimentalInTagComments ?? false,
1579
1662
  experimentalPatternedTemplate: state.mergedOptions.experimentalPatternedTemplate ?? false,
1580
1663
  experimentalServerScript: state.mergedOptions.experimentalServerScript ?? false,
1581
1664
  runtimeModuleName: state.mergedOptions.runtimeModuleName,
1582
1665
  runtimeGlobalName: state.mergedOptions.runtimeGlobalName,
1583
- vueVersion: state.mergedOptions.vueVersion
1666
+ vueVersion: state.mergedOptions.vueVersion,
1667
+ styleTrim: requestOptions.styleTrim,
1668
+ templateCacheHandlers: requestOptions.templateCacheHandlers,
1669
+ templateComments: requestOptions.templateComments,
1670
+ templateHoistStatic: requestOptions.templateHoistStatic,
1671
+ templatePrefixIdentifiers: requestOptions.templatePrefixIdentifiers
1584
1672
  };
1585
1673
  }
1586
1674
  function openCacheForRun(state, batchOptions) {
@@ -1662,7 +1750,10 @@ async function compileAll(state) {
1662
1750
  state.cache.set(file, restored);
1663
1751
  const metadata = currentMetadata.get(file);
1664
1752
  if (metadata) state.precompileMetadata.set(file, metadata);
1665
- syncCollectedCssForFile(state, file, restored);
1753
+ syncCollectedCssForFile({
1754
+ ...state,
1755
+ extractCss: state.extractCss && !isPluginVueCustomElement(state.mergedOptions, file)
1756
+ }, file, restored);
1666
1757
  restoredCount++;
1667
1758
  continue;
1668
1759
  }
@@ -1692,7 +1783,10 @@ async function compileAll(state) {
1692
1783
  const compiled = state.cache.get(fileResult.path);
1693
1784
  const sourceHash = sourceHashes.get(fileResult.path);
1694
1785
  if (compiled && sourceHash !== void 0) cache.set(fileResult.path, sourceHash, compiled);
1695
- syncCollectedCssForFile(state, fileResult.path, compiled);
1786
+ syncCollectedCssForFile({
1787
+ ...state,
1788
+ extractCss: state.extractCss && !isPluginVueCustomElement(state.mergedOptions, fileResult.path)
1789
+ }, fileResult.path, compiled);
1696
1790
  }
1697
1791
  }
1698
1792
  cache.retain(new Set(sfcFiles));
@@ -2619,6 +2713,13 @@ async function transformVizeVirtualModule(state, code, realPath, ssr, forceTypeS
2619
2713
  }
2620
2714
  }
2621
2715
  //#endregion
2716
+ //#region src/plugin/load-style.ts
2717
+ function normalizeStyleVirtualId(id) {
2718
+ const withoutPrefix = id.startsWith("\0") ? id.slice(1) : id;
2719
+ if (!withoutPrefix.includes("?vue")) return id;
2720
+ return withoutPrefix.replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
2721
+ }
2722
+ //#endregion
2622
2723
  //#region src/plugin/load.ts
2623
2724
  const SERVER_PLACEHOLDER_CODE = `import { createElementBlock, defineComponent } from "vue";
2624
2725
  export default defineComponent({
@@ -2649,11 +2750,6 @@ function findMacroArtifactModule(state, realPath, ssr, kind) {
2649
2750
  }, realPath, compiled);
2650
2751
  return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
2651
2752
  }
2652
- function normalizeStyleVirtualId(id) {
2653
- const withoutPrefix = id.startsWith("\0") ? id.slice(1) : id;
2654
- if (!withoutPrefix.includes("?vue")) return id;
2655
- return withoutPrefix.replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
2656
- }
2657
2753
  function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions) {
2658
2754
  const placeholderCode = getBoundaryPlaceholderCode(realPath, !!loadOptions?.ssr);
2659
2755
  if (placeholderCode) {
@@ -2664,7 +2760,8 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
2664
2760
  };
2665
2761
  }
2666
2762
  const cache = getEnvironmentCache(state, isSsr);
2667
- const extractCss = shouldExtractCssForRequest(state, isSsr);
2763
+ const customElement = isPluginVueCustomElement(state.mergedOptions, realPath);
2764
+ const extractCss = shouldExtractCssForRequest(state, isSsr) && !customElement;
2668
2765
  let compiled = cache.get(realPath);
2669
2766
  if (!compiled && fs.existsSync(realPath)) {
2670
2767
  state.logger.log(`load: on-demand compiling ${realPath}`);
@@ -2683,6 +2780,7 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
2683
2780
  ssr: isSsr,
2684
2781
  hmrUpdateType: loadOptions?.ssr ? void 0 : state.pendingHmrUpdateTypes.get(realPath),
2685
2782
  extractCss,
2783
+ customElement,
2686
2784
  filePath: realPath
2687
2785
  };
2688
2786
  if (compiled.css && !hasDelegated && embedsInlineCss(compiled, outputOptions)) compiled = {
@@ -2843,25 +2941,7 @@ async function transformHook(state, code, id, options) {
2843
2941
  return null;
2844
2942
  }
2845
2943
  //#endregion
2846
- //#region src/plugin/hmr.ts
2847
- const VIZE_COMPONENTS_CSS_BASENAME = "vize-components.css";
2848
- const VIZE_COMPONENTS_CSS_FILE = `assets/${VIZE_COMPONENTS_CSS_BASENAME}`;
2849
- /**
2850
- * The cached SFCs that pulled `dependencyFile` in through
2851
- * `<script src>` / `<template src>` / `<style src>`.
2852
- *
2853
- * This runs as the first statement of every hot update, before the `.vue` fast
2854
- * path, so editing an ordinary SFC pays for it too. It used to walk both caches
2855
- * end to end with a `path.resolve` per dependency, which made HMR latency grow
2856
- * with the number of components in the project; the caches now carry a reverse
2857
- * index that answers it in constant time. See `compiled-module-cache.ts`.
2858
- */
2859
- function getVueFilesDependingOn(state, dependencyFile) {
2860
- const normalizedDependency = path.resolve(dependencyFile);
2861
- const owners = /* @__PURE__ */ new Set();
2862
- for (const cache of [state.cache, state.ssrCache]) for (const vueFile of ownersOfDependency(cache, normalizedDependency)) owners.add(vueFile);
2863
- return [...owners];
2864
- }
2944
+ //#region src/plugin/hmr-module-graph.ts
2865
2945
  function unique(values) {
2866
2946
  return [...new Set(values)];
2867
2947
  }
@@ -2890,16 +2970,15 @@ function getStyleModuleFileCandidates(styleId) {
2890
2970
  }
2891
2971
  async function collectModulesByFile(server, fileIds) {
2892
2972
  const modules = /* @__PURE__ */ new Set();
2893
- const graph = server.moduleGraph;
2894
2973
  for (const fileId of fileIds) {
2895
2974
  const add = (module) => {
2896
2975
  if (module) modules.add(module);
2897
2976
  };
2898
- add(graph.getModuleById?.(fileId));
2977
+ add(server.moduleGraph.getModuleById?.(fileId));
2899
2978
  if (!fileId.startsWith("\0")) try {
2900
- add(await graph.getModuleByUrl?.(fileId));
2979
+ add(await server.moduleGraph.getModuleByUrl?.(fileId));
2901
2980
  } catch {}
2902
- for (const module of graph.getModulesByFile(fileId) ?? []) add(module);
2981
+ for (const module of server.moduleGraph.getModulesByFile(fileId) ?? []) add(module);
2903
2982
  }
2904
2983
  return modules;
2905
2984
  }
@@ -2914,17 +2993,48 @@ function preferAcceptingClientModules(modules, requireAcceptingClientModule = fa
2914
2993
  function invalidateModules(server, modules) {
2915
2994
  for (const module of modules) server.moduleGraph.invalidateModule(module);
2916
2995
  }
2996
+ //#endregion
2997
+ //#region src/plugin/hmr.ts
2998
+ const VIZE_COMPONENTS_CSS_BASENAME = "vize-components.css";
2999
+ const VIZE_COMPONENTS_CSS_FILE = `assets/${VIZE_COMPONENTS_CSS_BASENAME}`;
3000
+ /**
3001
+ * The cached SFCs that pulled `dependencyFile` in through
3002
+ * `<script src>` / `<template src>` / `<style src>`.
3003
+ *
3004
+ * This runs as the first statement of every hot update, before the `.vue` fast
3005
+ * path, so editing an ordinary SFC pays for it too. It used to walk both caches
3006
+ * end to end with a `path.resolve` per dependency, which made HMR latency grow
3007
+ * with the number of components in the project; the caches now carry a reverse
3008
+ * index that answers it in constant time. See `compiled-module-cache.ts`.
3009
+ */
3010
+ function getVueFilesDependingOn(state, dependencyFile) {
3011
+ const normalizedDependency = path.resolve(dependencyFile);
3012
+ const owners = /* @__PURE__ */ new Set();
3013
+ for (const cache of [state.cache, state.ssrCache]) for (const vueFile of ownersOfDependency(cache, normalizedDependency)) owners.add(vueFile);
3014
+ return [...owners];
3015
+ }
2917
3016
  async function handleHotUpdateHook(state, ctx, options = {}) {
2918
3017
  const { file, server, read } = ctx;
3018
+ const clientDependencyOwners = new Set(ownersOfDependency(state.cache, path.resolve(file)));
2919
3019
  const dependencyOwners = getVueFilesDependingOn(state, file);
2920
3020
  if (dependencyOwners.length > 0) {
2921
3021
  const affectedModules = /* @__PURE__ */ new Set();
2922
3022
  for (const vueFile of dependencyOwners) {
2923
3023
  const collectedModules = await collectModulesByFile(server, getVueModuleFileCandidates(vueFile));
2924
3024
  const modules = options.requireAcceptingClientModule ? preferAcceptingClientModules(collectedModules, true) : collectedModules;
2925
- if (options.requireAcceptingClientModule && modules.size === 0) continue;
2926
- state.cache.delete(vueFile);
2927
- state.ssrCache.delete(vueFile);
3025
+ if (options.requireAcceptingClientModule && modules.size === 0) {
3026
+ if (!options.ensureAcceptingClientModule || !clientDependencyOwners.has(vueFile)) continue;
3027
+ try {
3028
+ const ensured = await options.ensureAcceptingClientModule(vueFile);
3029
+ modules.add(ensured);
3030
+ } catch (error) {
3031
+ state.logger.error(`Failed to restore the client HMR owner for ${vueFile}:`, error);
3032
+ options.onRecompileError?.(error);
3033
+ return;
3034
+ }
3035
+ }
3036
+ evictCompiledModule(state.cache, vueFile);
3037
+ evictCompiledModule(state.ssrCache, vueFile);
2928
3038
  state.collectedCss.delete(vueFile);
2929
3039
  state.precompileMetadata.delete(vueFile);
2930
3040
  state.pendingHmrUpdateTypes.set(vueFile, "full-reload");
@@ -2962,6 +3072,15 @@ async function handleHotUpdateHook(state, ctx, options = {}) {
2962
3072
  state.logger.log(`Re-compiled: ${path.relative(state.root, file)} (${updateType})`);
2963
3073
  const modules = preferAcceptingClientModules(initialModules ?? await collectModulesByFile(server, getVueModuleFileCandidates(file)), options.requireAcceptingClientModule);
2964
3074
  const hasDelegated = hasDelegatedStyles(newCompiled);
3075
+ if (isPluginVueCustomElement(state.mergedOptions, file) && updateType === "style-only") {
3076
+ if (modules.size > 0) {
3077
+ state.pendingHmrUpdateTypes.set(file, "full-reload");
3078
+ invalidateModules(server, modules);
3079
+ return [...modules];
3080
+ }
3081
+ state.pendingHmrUpdateTypes.delete(file);
3082
+ return [];
3083
+ }
2965
3084
  if (hasDelegated && updateType === "style-only") {
2966
3085
  const affectedModules = /* @__PURE__ */ new Set();
2967
3086
  for (const block of newCompiled.styles ?? []) {
@@ -3044,6 +3163,7 @@ async function handleHotUpdateEnvironmentHook(state, environment, options) {
3044
3163
  ...options,
3045
3164
  server
3046
3165
  }, {
3166
+ ensureAcceptingClientModule: (vueFile) => environment.moduleGraph.ensureEntryFromUrl(toPluginVisibleVirtualId(vueFile), false),
3047
3167
  requireAcceptingClientModule: true,
3048
3168
  onRecompileError: () => {
3049
3169
  recompileFailed = true;
@@ -3066,6 +3186,10 @@ async function handleHotUpdateEnvironmentHook(state, environment, options) {
3066
3186
  */
3067
3187
  function createVueCompatPlugin(state, options) {
3068
3188
  let compilerSfc = null;
3189
+ const templateOptions = { compilerOptions: {
3190
+ directiveTransforms: {},
3191
+ nodeTransforms: []
3192
+ } };
3069
3193
  const loadCompilerSfc = () => {
3070
3194
  if (!compilerSfc) try {
3071
3195
  compilerSfc = createRequire(import.meta.url)("@vue/compiler-sfc");
@@ -3089,7 +3213,7 @@ function createVueCompatPlugin(state, options) {
3089
3213
  compiler: loadCompilerSfc(),
3090
3214
  isProduction: state.isProduction ?? false,
3091
3215
  root: state.root ?? process.cwd(),
3092
- template: {}
3216
+ template: templateOptions
3093
3217
  };
3094
3218
  },
3095
3219
  get include() {
@@ -3105,7 +3229,8 @@ function createVueCompatPlugin(state, options) {
3105
3229
  set exclude(value) {
3106
3230
  assertUnresolved("exclude");
3107
3231
  options.exclude = value;
3108
- }
3232
+ },
3233
+ version: PLUGIN_VUE_COMPAT_VERSION
3109
3234
  }
3110
3235
  };
3111
3236
  }
@@ -3746,10 +3871,7 @@ function resolveVueFeatureDefines(features, define) {
3746
3871
  };
3747
3872
  }
3748
3873
  //#endregion
3749
- //#region src/plugin/index.ts
3750
- function aliasSortKey(find) {
3751
- return typeof find === "string" ? find.length : find.source.length;
3752
- }
3874
+ //#region src/plugin/index-helpers.ts
3753
3875
  function shouldExtractCssForBuild(state, context) {
3754
3876
  if (!state.isProduction) return false;
3755
3877
  const environmentName = context.environment?.name;
@@ -3766,6 +3888,11 @@ function resolveCompatibilityOptions(options, compilerConfig = {}) {
3766
3888
  if (compatibility.hostCompiler === void 0 && isLegacyVueVersion(vueVersion)) compatibility.hostCompiler = true;
3767
3889
  return compatibility;
3768
3890
  }
3891
+ function aliasSortKey(find) {
3892
+ return typeof find === "string" ? find.length : find.source.length;
3893
+ }
3894
+ //#endregion
3895
+ //#region src/plugin/index.ts
3769
3896
  function vize(options = {}) {
3770
3897
  if (isLegacyVueCompatibilityMode(options)) return [createLegacyVueCompatibilityPlugin(options)];
3771
3898
  const state = {
@@ -3845,6 +3972,7 @@ function vize(options = {}) {
3845
3972
  sourceMap: options.sourceMap ?? compilerConfig.sourceMap,
3846
3973
  ...resolveExperimentalCompilerOptions(options, compilerConfig, sharedConfig?.experimentals),
3847
3974
  customRenderer: options.customRenderer ?? compilerConfig.customRenderer ?? false,
3975
+ customElements: options.customElements ?? compilerConfig.customElements,
3848
3976
  templateSyntax,
3849
3977
  compatibility,
3850
3978
  vueVersion,
@@ -3920,6 +4048,9 @@ function vize(options = {}) {
3920
4048
  async hotUpdate(options) {
3921
4049
  return handleHotUpdateEnvironmentHook(state, this.environment, options);
3922
4050
  },
4051
+ shouldTransformCachedModule({ id }) {
4052
+ return id?.includes(".vue") ? true : void 0;
4053
+ },
3923
4054
  async handleHotUpdate(ctx) {
3924
4055
  return handleHotUpdateHook(state, ctx);
3925
4056
  },
@@ -1,4 +1,4 @@
1
- import { f as ResolvedVizeConfig } from "../types-T_Fu8G5I.mjs";
1
+ import { f as ResolvedVizeConfig } from "../types-0tlI4YFk.mjs";
2
2
  import { ResolvedConfig } from "vite";
3
3
 
4
4
  //#region src/internal/config-bridge.d.ts
@@ -74,6 +74,10 @@ interface CompilerConfig {
74
74
  * Treat lowercase non-HTML tags as custom renderer elements
75
75
  */
76
76
  customRenderer?: boolean;
77
+ /**
78
+ * Tag patterns that compile as custom elements instead of Vue components
79
+ */
80
+ customElements?: string[];
77
81
  /**
78
82
  * Enable SSR mode
79
83
  */
@@ -409,6 +413,10 @@ interface LanguageServerConfig {
409
413
  * Enable completions
410
414
  */
411
415
  completion?: boolean;
416
+ /**
417
+ * Enable TypeScript signature help
418
+ */
419
+ signatureHelp?: boolean;
412
420
  /**
413
421
  * Enable hover information
414
422
  */
@@ -708,6 +716,36 @@ interface ExperimentalPluginOptions extends ExperimentalCompileFlags {
708
716
  experimentals?: ExperimentalOptions;
709
717
  }
710
718
  //#endregion
719
+ //#region src/compatibility-types.d.ts
720
+ type VizeVueVersion = 0.11 | 1 | 2 | "2.7" | 3 | "legacy";
721
+ interface VizeCompatibilityOptions {
722
+ /**
723
+ * Host Vue version. Vue 0.11/1/2/2.7 opt into host-compiler compatibility.
724
+ */
725
+ vueVersion?: VizeVueVersion;
726
+ /**
727
+ * Keep .vue files on the existing Vue compiler for legacy Vue runtimes.
728
+ * @default true when vueVersion is 0.11, 1, 2, "2.7", or "legacy"
729
+ */
730
+ hostCompiler?: boolean;
731
+ /**
732
+ * Enable function-body output for CDN/global Vue evaluation.
733
+ */
734
+ scriptSetupInStandalone?: boolean;
735
+ /**
736
+ * Allow Vapor output for Options API SFCs when vapor is enabled.
737
+ */
738
+ optionsApiVapor?: boolean;
739
+ /**
740
+ * Override the host Nuxt major when this option object is shared with Nuxt.
741
+ */
742
+ nuxtVersion?: 2 | 3 | 4;
743
+ /**
744
+ * Override the host Webpack major when this option object is shared with unplugin.
745
+ */
746
+ webpackVersion?: 4 | 5;
747
+ }
748
+ //#endregion
711
749
  //#region src/inspector-types.d.ts
712
750
  interface VizeInspectorLintPlanRequest {
713
751
  /** Project-relative files whose effective lint rules should be explained. */
@@ -721,6 +759,36 @@ interface VizeInspectorOptions {
721
759
  lintPlan?: VizeInspectorLintPlanProvider;
722
760
  }
723
761
  //#endregion
762
+ //#region src/plugin-vue-types.d.ts
763
+ type VitePluginVueFilterPattern = string | RegExp | (string | RegExp)[];
764
+ type VitePluginVueCustomElementOption = boolean | VitePluginVueFilterPattern;
765
+ type VitePluginVueComponentIdGenerator = "filepath" | "filepath-source" | ((filepath: string, source: string, isProduction: boolean, getHash: (text: string) => string) => string);
766
+ interface VitePluginVueScriptOptions {
767
+ hoistStatic?: boolean;
768
+ propsDestructure?: boolean | "error";
769
+ globalTypeFiles?: string[];
770
+ [key: string]: unknown;
771
+ }
772
+ interface VitePluginVueTemplateCompilerOptions {
773
+ comments?: boolean;
774
+ hoistStatic?: boolean;
775
+ cacheHandlers?: boolean;
776
+ prefixIdentifiers?: boolean;
777
+ [key: string]: unknown;
778
+ }
779
+ interface VitePluginVueTemplateOptions {
780
+ compilerOptions?: VitePluginVueTemplateCompilerOptions;
781
+ transformAssetUrls?: boolean | Record<string, unknown>;
782
+ preprocessCustomRequire?: unknown;
783
+ preprocessOptions?: Record<string, unknown>;
784
+ [key: string]: unknown;
785
+ }
786
+ interface VitePluginVueStyleOptions {
787
+ trim?: boolean;
788
+ inMap?: unknown;
789
+ [key: string]: unknown;
790
+ }
791
+ //#endregion
724
792
  //#region src/vue-features.d.ts
725
793
  /** Vue runtime feature flags shared with `@vitejs/plugin-vue`. */
726
794
  interface VizeVueFeatures {
@@ -740,6 +808,12 @@ interface VizeVueFeatures {
740
808
  * @default false
741
809
  */
742
810
  prodHydrationMismatchDetails?: boolean;
811
+ /** Custom-element matcher from `@vitejs/plugin-vue`'s `features` bag. */
812
+ customElement?: VitePluginVueCustomElementOption;
813
+ /** Vue 3.5 reactive props destructure feature flag. */
814
+ propsDestructure?: boolean | "error";
815
+ /** Scope-id strategy hook accepted for plugin-vue config compatibility. */
816
+ componentIdGenerator?: VitePluginVueComponentIdGenerator;
743
817
  }
744
818
  //#endregion
745
819
  //#region src/utils/module-output.d.ts
@@ -764,7 +838,7 @@ type ModuleOutputInfo = {
764
838
  defaultExportIsSfcMain: boolean;
765
839
  };
766
840
  //#endregion
767
- //#region src/types.d.ts
841
+ //#region src/sfc-types.d.ts
768
842
  interface MacroArtifact {
769
843
  kind: string;
770
844
  name: string;
@@ -774,34 +848,51 @@ interface MacroArtifact {
774
848
  start: number;
775
849
  end: number;
776
850
  }
777
- type VizeVueVersion = 0.11 | 1 | 2 | "2.7" | 3 | "legacy";
778
- interface VizeCompatibilityOptions {
779
- /**
780
- * Host Vue version. Vue 0.11/1/2/2.7 opt into host-compiler compatibility.
781
- */
782
- vueVersion?: VizeVueVersion;
783
- /**
784
- * Keep .vue files on the existing Vue compiler for legacy Vue runtimes.
785
- * @default true when vueVersion is 0.11, 1, 2, "2.7", or "legacy"
786
- */
787
- hostCompiler?: boolean;
788
- /**
789
- * Enable function-body output for CDN/global Vue evaluation.
790
- */
791
- scriptSetupInStandalone?: boolean;
792
- /**
793
- * Allow Vapor output for Options API SFCs when vapor is enabled.
794
- */
795
- optionsApiVapor?: boolean;
851
+ interface StyleBlockInfo {
852
+ /** Raw style content (uncompiled for preprocessor langs) */
853
+ content: string;
854
+ /** External source path from `<style src>`, when present */
855
+ src?: string | null;
856
+ /** Language of the style block (e.g., "css", "scss", "less", "sass", "stylus") */
857
+ lang: string | null;
858
+ /** Whether the style block has the scoped attribute */
859
+ scoped: boolean;
860
+ /** CSS Modules: true for unnamed `module`, or the binding name for `module="name"` */
861
+ module: boolean | string;
862
+ /** Index of this style block in the SFC */
863
+ index: number;
864
+ }
865
+ interface CompiledModule {
866
+ code: string;
796
867
  /**
797
- * Override the host Nuxt major when this option object is shared with Nuxt.
868
+ * Source Map v3 document (JSON) describing `code`, when the compiler was
869
+ * asked for one (#3399). Absent when source maps are off, when the SFC has no
870
+ * script block, and for the rspack and unplugin builders, which do not request
871
+ * maps. Persisted with the rest of the module in the pre-compile cache.
798
872
  */
799
- nuxtVersion?: 2 | 3 | 4;
873
+ map?: string;
874
+ css?: string;
875
+ scopeId: string;
876
+ hasScoped: boolean;
877
+ templateHash?: string;
878
+ styleHash?: string;
879
+ scriptHash?: string;
880
+ /** Compile-time macro artifacts extracted from the source SFC */
881
+ macroArtifacts?: MacroArtifact[];
882
+ /** Per-block style metadata extracted from the source SFC */
883
+ styles?: StyleBlockInfo[];
884
+ /** Files loaded through SFC `src` imports */
885
+ dependencies?: string[];
800
886
  /**
801
- * Override the host Webpack major when this option object is shared with unplugin.
887
+ * Module shape reported by the native compiler, so `generateOutput` need not
888
+ * re-parse the emitted module (#3425). Absent for a cache entry written before
889
+ * the field existed, and for the rspack and unplugin builders, which never set
890
+ * it — both fall back to parsing.
802
891
  */
803
- webpackVersion?: 4 | 5;
892
+ moduleShape?: ModuleOutputInfo;
804
893
  }
894
+ //#endregion
895
+ //#region src/types.d.ts
805
896
  interface VizeOptions extends ExperimentalPluginOptions {
806
897
  /**
807
898
  * Inline shared Vize config for Vite Plus-first projects.
@@ -812,6 +903,19 @@ interface VizeOptions extends ExperimentalPluginOptions {
812
903
  inspector?: VizeInspectorOptions;
813
904
  /** Vue runtime feature flags compatible with `@vitejs/plugin-vue`. */
814
905
  features?: VizeVueFeatures;
906
+ /** `@vitejs/plugin-vue` script option bag accepted for drop-in config parity. */
907
+ script?: VitePluginVueScriptOptions;
908
+ /** `@vitejs/plugin-vue` template option bag. */
909
+ template?: VitePluginVueTemplateOptions;
910
+ /** `@vitejs/plugin-vue` style option bag. */
911
+ style?: VitePluginVueStyleOptions;
912
+ /** Lower-level compiler override accepted for plugin-vue config parity. */
913
+ compiler?: unknown;
914
+ /**
915
+ * Top-level custom-element matcher supported by `@vitejs/plugin-vue`.
916
+ * @default /\.ce\.vue$/
917
+ */
918
+ customElement?: VitePluginVueCustomElementOption;
815
919
  /**
816
920
  * Vue major version for the host project.
817
921
  *
@@ -894,6 +998,11 @@ interface VizeOptions extends ExperimentalPluginOptions {
894
998
  * @default false
895
999
  */
896
1000
  customRenderer?: boolean;
1001
+ /**
1002
+ * Tag patterns that compile as custom elements instead of Vue components.
1003
+ * Supports exact tags and `*` wildcards, e.g. `["Tres*", "primitive"]`.
1004
+ */
1005
+ customElements?: string[];
897
1006
  /**
898
1007
  * Template syntax compatibility mode.
899
1008
  * @default "standard"
@@ -947,48 +1056,5 @@ interface VizeOptions extends ExperimentalPluginOptions {
947
1056
  */
948
1057
  debug?: boolean;
949
1058
  }
950
- interface StyleBlockInfo {
951
- /** Raw style content (uncompiled for preprocessor langs) */
952
- content: string;
953
- /** External source path from `<style src>`, when present */
954
- src?: string | null;
955
- /** Language of the style block (e.g., "css", "scss", "less", "sass", "stylus") */
956
- lang: string | null;
957
- /** Whether the style block has the scoped attribute */
958
- scoped: boolean;
959
- /** CSS Modules: true for unnamed `module`, or the binding name for `module="name"` */
960
- module: boolean | string;
961
- /** Index of this style block in the SFC */
962
- index: number;
963
- }
964
- interface CompiledModule {
965
- code: string;
966
- /**
967
- * Source Map v3 document (JSON) describing `code`, when the compiler was
968
- * asked for one (#3399). Absent when source maps are off, when the SFC has no
969
- * script block, and for the rspack and unplugin builders, which do not request
970
- * maps. Persisted with the rest of the module in the pre-compile cache.
971
- */
972
- map?: string;
973
- css?: string;
974
- scopeId: string;
975
- hasScoped: boolean;
976
- templateHash?: string;
977
- styleHash?: string;
978
- scriptHash?: string;
979
- /** Compile-time macro artifacts extracted from the source SFC */
980
- macroArtifacts?: MacroArtifact[];
981
- /** Per-block style metadata extracted from the source SFC */
982
- styles?: StyleBlockInfo[];
983
- /** Files loaded through SFC `src` imports */
984
- dependencies?: string[];
985
- /**
986
- * Module shape reported by the native compiler, so `generateOutput` need not
987
- * re-parse the emitted module (#3425). Absent for a cache entry written before
988
- * the field existed, and for the rspack and unplugin builders, which never set
989
- * it — both fall back to parsing.
990
- */
991
- moduleShape?: ModuleOutputInfo;
992
- }
993
1059
  //#endregion
994
- export { VizeVueVersion as a, VizeInspectorLintPlanRequest as c, LoadConfigOptions as d, ResolvedVizeConfig as f, VizeOptions as i, VizeInspectorOptions as l, VizeConfig as m, MacroArtifact as n, VizeVueFeatures as o, UserConfigExport as p, VizeCompatibilityOptions as r, VizeInspectorLintPlanProvider as s, CompiledModule as t, ConfigEnv as u };
1060
+ export { VizeInspectorLintPlanProvider as a, VizeCompatibilityOptions as c, LoadConfigOptions as d, ResolvedVizeConfig as f, VizeVueFeatures as i, VizeVueVersion as l, VizeConfig as m, CompiledModule as n, VizeInspectorLintPlanRequest as o, UserConfigExport as p, MacroArtifact as r, VizeInspectorOptions as s, VizeOptions as t, ConfigEnv as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.345.0",
3
+ "version": "0.350.2",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -45,16 +45,16 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@vizejs/native": "0.345.0",
49
- "oxc-parser": "0.133.0",
50
- "tinyglobby": "0.2.16",
51
- "vize": "0.345.0"
48
+ "@vizejs/native": "0.350.2",
49
+ "oxc-parser": "0.144.0",
50
+ "tinyglobby": "0.2.17",
51
+ "vize": "0.350.2"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/node": "25.9.2",
55
55
  "typescript": "6.0.3",
56
- "vite": "npm:@voidzero-dev/vite-plus-core@0.1.21",
57
- "vite-plus": "0.1.21"
56
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.1.24",
57
+ "vite-plus": "0.1.24"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "vite": "^7.3.0 || ^8.0.0"