@vizejs/vite-plugin 0.133.0 → 0.135.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.
Files changed (2) hide show
  1. package/dist/index.mjs +75 -46
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -581,9 +581,12 @@ function shouldCompileVueSfcRequest(request) {
581
581
  if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
582
582
  return params.has("nuxt_component");
583
583
  }
584
- async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules) {
584
+ function hasNuxtComponentQuery$1(request) {
585
+ if (!request.querySuffix) return false;
586
+ return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
587
+ }
588
+ async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, querySuffix, preserveQueryAsPath) {
585
589
  if (path.isAbsolute(id)) return null;
586
- const request = classifyVitePluginRequest(id);
587
590
  const viteImporter = normalizeViteRequireBase(importer) ?? importer;
588
591
  const viteResolved = await ctx.resolve(id, viteImporter, { skipSelf: true });
589
592
  const realPath = viteResolved ? normalizeResolvedVuePath(viteResolved.id) : null;
@@ -599,7 +602,7 @@ async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, h
599
602
  }
600
603
  if (state.cache.has(realPath) || fs.existsSync(realPath)) {
601
604
  state.logger.log(`resolveId: resolved via Vite fallback ${id} to ${realPath}`);
602
- return `${toVirtualId(realPath, isSsrRequest)}${request.querySuffix}`;
605
+ return preserveQueryAsPath ? `${realPath}${querySuffix}` : `${toVirtualId(realPath, isSsrRequest)}${querySuffix}`;
603
606
  }
604
607
  return null;
605
608
  }
@@ -649,7 +652,17 @@ async function resolveIdHook(ctx, state, id, importer, options) {
649
652
  const resolved = resolveVuePath(state, request.path, importer);
650
653
  if (resolved && fs.existsSync(resolved)) return `\0${resolved}${request.querySuffix}`;
651
654
  }
652
- if (request.isVueStyleQuery && request.styleVirtualSuffix) return `\0${id}${request.styleVirtualSuffix}`;
655
+ if (request.isVueStyleQuery && request.styleVirtualSuffix) {
656
+ if (id.includes("vitepress-plugin-llms")) {
657
+ state.logger.log(`resolveId: skipping vitepress-plugin-llms style import ${id}`);
658
+ return null;
659
+ }
660
+ if (!(state.mergedOptions.handleNodeModulesVue ?? true) && request.path.includes("node_modules")) {
661
+ state.logger.log(`resolveId: skipping node_modules style import ${id}`);
662
+ return null;
663
+ }
664
+ return `\0${id}${request.styleVirtualSuffix}`;
665
+ }
653
666
  const isMacroImporter = importerRequest?.isMacroVirtualId ?? false;
654
667
  const isVizeVirtualImporter = importerRequest?.isVizeVirtual ?? false;
655
668
  if (importer && (isVizeVirtualImporter || isMacroImporter)) {
@@ -783,7 +796,8 @@ async function resolveIdHook(ctx, state, id, importer, options) {
783
796
  }
784
797
  }
785
798
  if (shouldCompileVueSfcRequest(request)) {
786
- const handleNodeModules = state.initialized ? state.mergedOptions.handleNodeModulesVue ?? true : true;
799
+ const handleNodeModules = state.mergedOptions.handleNodeModulesVue ?? true;
800
+ const preserveQueryAsPath = hasNuxtComponentQuery$1(request);
787
801
  const vueRequestPath = request.path;
788
802
  if (!handleNodeModules && vueRequestPath.includes("node_modules")) {
789
803
  state.logger.log(`resolveId: skipping node_modules import ${id}`);
@@ -792,7 +806,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
792
806
  const resolved = resolveVuePath(state, vueRequestPath, importer);
793
807
  const fileExists = fs.existsSync(resolved);
794
808
  if (!fileExists) {
795
- const aliased = await resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules);
809
+ const aliased = await resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, request.querySuffix, preserveQueryAsPath);
796
810
  if (aliased) return aliased;
797
811
  }
798
812
  const isNodeModulesPath = resolved.includes("node_modules");
@@ -806,7 +820,10 @@ async function resolveIdHook(ctx, state, id, importer, options) {
806
820
  }
807
821
  const hasCache = state.cache.has(resolved);
808
822
  state.logger.log(`resolveId: id=${id}, resolved=${resolved}, hasCache=${hasCache}, fileExists=${fileExists}, importer=${importer ?? "none"}`);
809
- if (hasCache || fileExists) return `${toVirtualId(resolved, isSsrRequest)}${request.querySuffix}`;
823
+ if (hasCache || fileExists) {
824
+ if (preserveQueryAsPath) return `${resolved}${request.querySuffix}`;
825
+ return `${toVirtualId(resolved, isSsrRequest)}${request.querySuffix}`;
826
+ }
810
827
  }
811
828
  return null;
812
829
  }
@@ -855,6 +872,48 @@ function findMacroArtifactModule(state, realPath, ssr, kind) {
855
872
  }
856
873
  return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
857
874
  }
875
+ function hasNuxtComponentQuery(request) {
876
+ if (!request.querySuffix) return false;
877
+ return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
878
+ }
879
+ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions) {
880
+ const placeholderCode = getBoundaryPlaceholderCode(realPath, !!loadOptions?.ssr);
881
+ if (placeholderCode) {
882
+ state.logger.log(`load: using boundary placeholder for ${realPath}`);
883
+ return {
884
+ code: placeholderCode,
885
+ map: null
886
+ };
887
+ }
888
+ const cache = getEnvironmentCache(state, isSsr);
889
+ let compiled = cache.get(realPath);
890
+ if (!compiled && fs.existsSync(realPath)) {
891
+ state.logger.log(`load: on-demand compiling ${realPath}`);
892
+ compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr));
893
+ syncCollectedCssForFile(state, realPath, compiled);
894
+ }
895
+ if (!compiled) return null;
896
+ const hasDelegated = hasDelegatedStyles(compiled);
897
+ const pendingHmrUpdateType = loadOptions?.ssr ? void 0 : state.pendingHmrUpdateTypes.get(realPath);
898
+ if (compiled.css && !hasDelegated) compiled = {
899
+ ...compiled,
900
+ css: resolveCssImports(compiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase)
901
+ };
902
+ const generatedOutput = generateOutput(compiled, {
903
+ isProduction: state.isProduction,
904
+ isDev: state.server !== null && !isSsr,
905
+ ssr: isSsr,
906
+ hmrUpdateType: pendingHmrUpdateType,
907
+ extractCss: state.extractCss,
908
+ filePath: realPath
909
+ });
910
+ const output = rewriteStaticAssetUrls(rewriteDynamicTemplateImports(isSsr ? normalizeVueServerRendererImport(generatedOutput) : generatedOutput, state.dynamicImportAliasRules), state.dynamicImportAliasRules);
911
+ if (!loadOptions?.ssr) state.pendingHmrUpdateTypes.delete(realPath);
912
+ return {
913
+ code: output,
914
+ map: null
915
+ };
916
+ }
858
917
  function loadDefinePageArtifact(state, realPath, ssr) {
859
918
  return {
860
919
  code: findMacroArtifactModule(state, realPath, ssr, "vue-router.definePage") ?? "export default {}",
@@ -869,9 +928,11 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
869
928
  } : null;
870
929
  }
871
930
  function loadHook(state, id, loadOptions) {
872
- if (id !== "\0vize:all-styles.css" && !id.startsWith("\0")) return null;
873
- const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
874
931
  const request = classifyVitePluginRequest(id);
932
+ if (id !== "\0vize:all-styles.css" && !id.startsWith("\0")) {
933
+ if (!request.isVueSfcPath || !hasNuxtComponentQuery(request)) return null;
934
+ }
935
+ const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
875
936
  if (id === "\0vize:all-styles.css") {
876
937
  let allCss = "";
877
938
  for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
@@ -921,43 +982,11 @@ function loadHook(state, id, loadOptions) {
921
982
  state.logger.log(`load: skipping non-vue virtual module ${realPath}`);
922
983
  return null;
923
984
  }
924
- const placeholderCode = getBoundaryPlaceholderCode(realPath, !!loadOptions?.ssr);
925
- if (placeholderCode) {
926
- state.logger.log(`load: using boundary placeholder for ${realPath}`);
927
- return {
928
- code: placeholderCode,
929
- map: null
930
- };
931
- }
932
- const cache = getEnvironmentCache(state, isSsr);
933
- let compiled = cache.get(realPath);
934
- if (!compiled && fs.existsSync(realPath)) {
935
- state.logger.log(`load: on-demand compiling ${realPath}`);
936
- compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr));
937
- syncCollectedCssForFile(state, realPath, compiled);
938
- }
939
- if (compiled) {
940
- const hasDelegated = hasDelegatedStyles(compiled);
941
- const pendingHmrUpdateType = loadOptions?.ssr ? void 0 : state.pendingHmrUpdateTypes.get(realPath);
942
- if (compiled.css && !hasDelegated) compiled = {
943
- ...compiled,
944
- css: resolveCssImports(compiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase)
945
- };
946
- const generatedOutput = generateOutput(compiled, {
947
- isProduction: state.isProduction,
948
- isDev: state.server !== null && !isSsr,
949
- ssr: isSsr,
950
- hmrUpdateType: pendingHmrUpdateType,
951
- extractCss: state.extractCss,
952
- filePath: realPath
953
- });
954
- const output = rewriteStaticAssetUrls(rewriteDynamicTemplateImports(isSsr ? normalizeVueServerRendererImport(generatedOutput) : generatedOutput, state.dynamicImportAliasRules), state.dynamicImportAliasRules);
955
- if (!loadOptions?.ssr) state.pendingHmrUpdateTypes.delete(realPath);
956
- return {
957
- code: output,
958
- map: null
959
- };
960
- }
985
+ return loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions);
986
+ }
987
+ if (request.isVueSfcPath && hasNuxtComponentQuery(request)) {
988
+ const realPath = classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
989
+ return loadCompiledSfcModule(state, realPath, !!loadOptions?.ssr, currentBase, loadOptions);
961
990
  }
962
991
  if (id.startsWith("\0")) {
963
992
  const afterPrefix = id.startsWith("\0vize:") ? id.slice(6) : id.slice(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.133.0",
3
+ "version": "0.135.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -39,9 +39,9 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@vizejs/native": "0.133.0",
42
+ "@vizejs/native": "0.135.0",
43
43
  "tinyglobby": "0.2.16",
44
- "vize": "0.133.0"
44
+ "vize": "0.135.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "25.7.0",