@vizejs/vite-plugin 0.134.0 → 0.137.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/README.md CHANGED
@@ -149,6 +149,13 @@ export default defineNuxtConfig({
149
149
 
150
150
  ```ts
151
151
  interface VizeNativeOptions {
152
+ /**
153
+ * Vue major version for the host project.
154
+ * Set to 0.11, 1, 2, or "legacy" to let the existing compiler plugin/loader handle SFCs.
155
+ * @default 3
156
+ */
157
+ vueVersion?: 0.11 | 1 | 2 | 3 | "legacy";
158
+
152
159
  /**
153
160
  * Files to include in compilation
154
161
  * @default /\.vue$/
@@ -205,6 +212,19 @@ interface VizeNativeOptions {
205
212
  }
206
213
  ```
207
214
 
215
+ ### Legacy Vue / Nuxt 2 compatibility
216
+
217
+ Vize's native SFC compiler targets Vue 3 runtime output. In Vue 0.11, Vue 1, Vue 2,
218
+ and Nuxt 2 projects, keep the existing host compiler in charge and set:
219
+
220
+ ```ts
221
+ vize({ vueVersion: 2 });
222
+ ```
223
+
224
+ Use `0.11`, `1`, `2`, or `"legacy"` for the same host-compiler compatibility mode. This makes the
225
+ plugin non-invasive: it does not intercept `.vue` requests, does not expose the Vue 3 `vite:vue`
226
+ compatibility API, and does not inject Vue 3 bundler feature flags.
227
+
208
228
  ## How It Works
209
229
 
210
230
  ### Pre-compilation at Startup
package/dist/index.d.mts CHANGED
@@ -584,12 +584,24 @@ interface MacroArtifact {
584
584
  start: number;
585
585
  end: number;
586
586
  }
587
+ type VizeVueVersion = 0.11 | 1 | 2 | 3 | "legacy";
587
588
  interface VizeOptions {
588
589
  /**
589
590
  * Inline shared Vize config for Vite Plus-first projects.
590
591
  * Direct plugin options still take precedence over these values.
591
592
  */
592
593
  config?: UserConfigExport;
594
+ /**
595
+ * Vue major version for the host project.
596
+ *
597
+ * Legacy Vue projects must keep their existing compiler plugin/loader in
598
+ * charge of SFC compilation. Set this to `0.11`, `1`, `2`, or `"legacy"` to
599
+ * make Vize a non-invasive compatibility plugin that does not intercept
600
+ * `.vue` requests or inject Vue 3 bundler defines.
601
+ *
602
+ * @default 3
603
+ */
604
+ vueVersion?: VizeVueVersion;
593
605
  /**
594
606
  * Override the public base used for dev-time asset URLs such as /@fs paths.
595
607
  * Useful for frameworks like Nuxt that serve Vite from a subpath (e.g. /_nuxt/).
@@ -742,4 +754,4 @@ declare const __internal: {
742
754
  rewriteStaticAssetUrls: typeof rewriteStaticAssetUrls;
743
755
  };
744
756
  //#endregion
745
- export { type CompiledModule, type LoadConfigOptions, type MacroArtifact, type ResolvedVizeConfig, type UserConfigExport, type VizeConfig, type VizeOptions, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, resolveConfigExport, vizeConfigStore };
757
+ export { type CompiledModule, type LoadConfigOptions, type MacroArtifact, type ResolvedVizeConfig, type UserConfigExport, type VizeConfig, type VizeOptions, type VizeVueVersion, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, resolveConfigExport, vizeConfigStore };
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);
@@ -1244,6 +1273,19 @@ function installVirtualAssetMiddleware(devServer, state) {
1244
1273
  });
1245
1274
  }
1246
1275
  //#endregion
1276
+ //#region src/plugin/vue-version.ts
1277
+ function isLegacyVueCompatibilityMode(options) {
1278
+ return options.vueVersion !== void 0 && options.vueVersion !== 3;
1279
+ }
1280
+ function createLegacyVueCompatibilityPlugin(options) {
1281
+ return {
1282
+ name: "vite-plugin-vize:legacy-vue-compat",
1283
+ configResolved(resolvedConfig) {
1284
+ createLogger(options.debug ?? false).log(`Legacy Vue compatibility mode is active for ${resolvedConfig.root}; Vize will not compile .vue files.`);
1285
+ }
1286
+ };
1287
+ }
1288
+ //#endregion
1247
1289
  //#region src/plugin/index.ts
1248
1290
  function aliasSortKey(find) {
1249
1291
  return typeof find === "string" ? find.length : find.source.length;
@@ -1290,6 +1332,7 @@ function mergeSharedConfig(baseConfig, overrideConfig) {
1290
1332
  };
1291
1333
  }
1292
1334
  function vize(options = {}) {
1335
+ if (isLegacyVueCompatibilityMode(options)) return [createLegacyVueCompatibilityPlugin(options)];
1293
1336
  const state = {
1294
1337
  cache: /* @__PURE__ */ new Map(),
1295
1338
  ssrCache: /* @__PURE__ */ new Map(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.134.0",
3
+ "version": "0.137.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.134.0",
42
+ "@vizejs/native": "0.137.0",
43
43
  "tinyglobby": "0.2.16",
44
- "vize": "0.134.0"
44
+ "vize": "0.137.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "25.7.0",