@vizejs/vite-plugin 0.243.0 → 0.263.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.d.mts CHANGED
@@ -1,11 +1,10 @@
1
- import { defineConfig, loadConfig, resolveConfigExport } from "vize";
2
1
  import { Plugin } from "vite";
3
2
 
4
3
  //#region ../../cli/src/types/generated.d.ts
5
4
  /**
6
5
  * Host Vue runtime version for opt-in compatibility modes
7
6
  */
8
- type VueVersion = 0.11 | 1 | 2 | 3 | "legacy";
7
+ type VueVersion = "3" | "2.7" | "2" | "1" | "0.11" | "0.10";
9
8
  /**
10
9
  * Configuration file for vize - High-performance Vue.js toolchain
11
10
  */
@@ -223,21 +222,21 @@ interface TypeCheckerConfig {
223
222
  * Check fallthrough attrs on multi-root templates
224
223
  */
225
224
  checkFallthroughAttrs?: boolean;
226
- /**
227
- * Resolve Vue 3 Options API template bindings (data/computed/methods/inject/setup/props) during type checking. Opt-in; available in the standard build (not a legacy feature).
228
- */
225
+ /** Resolve Vue 3 Options API template bindings during type checking. */
229
226
  optionsApi?: boolean;
230
227
  /**
231
228
  * Enable Vue 2.7 / Nuxt 2 Options API template binding support
232
229
  */
233
230
  legacyVue2?: boolean;
234
231
  /**
235
- * Path to tsconfig.json
232
+ * Opt-in type-checking of .jsx/.tsx Vue components (#1497). Default-off so mixed Vue/React repositories do not accidentally route React .tsx through the Vue JSX checker. Set to true to route .jsx/.tsx through the Vize JSX virtual-TS path.
236
233
  */
237
- tsconfig?: string;
234
+ jsxTypecheck?: boolean;
238
235
  /**
239
- * Path to the Corsa executable. This is the canonical runtime key; tsgoPath is kept as a compatibility alias.
236
+ * Path to tsconfig.json
240
237
  */
238
+ tsconfig?: string;
239
+ /** Path to the Corsa executable. tsgoPath is kept as a compatibility alias. */
241
240
  corsaPath?: string;
242
241
  /**
243
242
  * Deprecated alias for typeChecker.corsaPath
@@ -635,15 +634,15 @@ interface MacroArtifact {
635
634
  start: number;
636
635
  end: number;
637
636
  }
638
- type VizeVueVersion = 0.11 | 1 | 2 | 3 | "legacy";
637
+ type VizeVueVersion = 0.11 | 1 | 2 | "2.7" | 3 | "legacy";
639
638
  interface VizeCompatibilityOptions {
640
639
  /**
641
- * Host Vue version. Vue 0.11/1/2 opt into host-compiler compatibility.
640
+ * Host Vue version. Vue 0.11/1/2/2.7 opt into host-compiler compatibility.
642
641
  */
643
642
  vueVersion?: VizeVueVersion;
644
643
  /**
645
644
  * Keep .vue files on the existing Vue compiler for legacy Vue runtimes.
646
- * @default true when vueVersion is 0.11, 1, 2, or "legacy"
645
+ * @default true when vueVersion is 0.11, 1, 2, "2.7", or "legacy"
647
646
  */
648
647
  hostCompiler?: boolean;
649
648
  /**
@@ -851,6 +850,10 @@ declare function rewriteStaticAssetUrls(code: string, aliasRules: DynamicImportA
851
850
  declare function vize(options?: VizeOptions): Plugin[];
852
851
  //#endregion
853
852
  //#region src/config.d.ts
853
+ declare function defineConfig(config: UserConfigExport): UserConfigExport;
854
+ declare function loadConfig(root: string, options?: LoadConfigOptions): Promise<ResolvedVizeConfig | null>;
855
+ declare function resolveConfigExport(exported: UserConfigExport, env?: ConfigEnv): Promise<ResolvedVizeConfig>;
856
+ declare const VIZE_CONFIG_FILE_ENV = "VIZE_CONFIG_FILE";
854
857
  /**
855
858
  * Shared config store for inter-plugin communication.
856
859
  * Key = project root, Value = resolved VizeConfig.
@@ -863,4 +866,4 @@ declare const __internal: {
863
866
  rewriteStaticAssetUrls: typeof rewriteStaticAssetUrls;
864
867
  };
865
868
  //#endregion
866
- export { type CompiledModule, type LoadConfigOptions, type MacroArtifact, type ResolvedVizeConfig, type UserConfigExport, type VizeCompatibilityOptions, type VizeConfig, type VizeOptions, type VizeVueVersion, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, resolveConfigExport, vizeConfigStore };
869
+ export { type CompiledModule, type LoadConfigOptions, type MacroArtifact, type ResolvedVizeConfig, type UserConfigExport, VIZE_CONFIG_FILE_ENV, type VizeCompatibilityOptions, type VizeConfig, type VizeOptions, type VizeVueVersion, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, resolveConfigExport, vizeConfigStore };
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@ import { createRequire } from "node:module";
2
2
  import { createHash } from "node:crypto";
3
3
  import * as native from "@vizejs/native";
4
4
  import { applyViteDefineReplacements, chunkVitePrecompileFiles, classifyVitePluginRequest, createViteBareImportBases, createViteBareImportCandidates, createViteVirtualId, detectViteHmrUpdateType, diffVitePrecompileFiles, generateViteHmrCode, hasViteHmrChanges, isViteBareSpecifier, normalizeViteCssModuleFilename, normalizeViteDevMiddlewareUrl, normalizeVitePrecompileBatchSize, normalizeViteRequireBase, normalizeViteResolvedVuePath, resolveViteAliasRequest, resolveViteCssImports, resolveViteRelativeImport, resolveViteVuePath, rewriteViteDynamicTemplateImports, rewriteViteImportMetaGlobBase, rewriteViteStaticAssetUrls, scopeViteCssForPipeline, shouldApplyViteDefineInVirtualModule, splitViteIdQuery, toViteBrowserImportPrefix, transformViteCssVarsForPipeline } from "@vizejs/native";
5
- import { CONFIG_FILE_NAMES, defineConfig, loadConfig, resolveConfigExport } from "vize";
6
5
  import fs from "node:fs";
7
6
  import { glob } from "tinyglobby";
8
7
  import path from "node:path";
@@ -10,7 +9,8 @@ import { pathToFileURL } from "node:url";
10
9
  import * as vite from "vite";
11
10
  //#region src/hmr.ts
12
11
  function hasHmrChanges(prev, next) {
13
- return hasViteHmrChanges(toHmrHashes(prev), toHmrHashes(next));
12
+ if (!prev) return true;
13
+ return hasViteHmrChanges(toHmrHashes(prev), toHmrHashes(next)) || runtimeFingerprint(prev) !== runtimeFingerprint(next) || styleFingerprint(prev) !== styleFingerprint(next);
14
14
  }
15
15
  /**
16
16
  * Detect the type of HMR update needed based on content hash changes.
@@ -20,7 +20,13 @@ function hasHmrChanges(prev, next) {
20
20
  * @returns The type of HMR update needed
21
21
  */
22
22
  function detectHmrUpdateType(prev, next) {
23
- return detectViteHmrUpdateType(toHmrHashes(prev), toHmrHashes(next));
23
+ if (!prev) return detectViteHmrUpdateType(void 0, toHmrHashes(next));
24
+ if (prev.scriptHash !== next.scriptHash) return "full-reload";
25
+ if (prev.templateHash !== next.templateHash) return "template-only";
26
+ if (prev.styleHash !== next.styleHash) return "style-only";
27
+ if (runtimeFingerprint(prev) !== runtimeFingerprint(next)) return "full-reload";
28
+ if (styleFingerprint(prev) !== styleFingerprint(next)) return "style-only";
29
+ return "full-reload";
24
30
  }
25
31
  /**
26
32
  * Generate HMR-aware code output based on update type.
@@ -35,6 +41,38 @@ function toHmrHashes(module) {
35
41
  styleHash: module.styleHash
36
42
  } : void 0;
37
43
  }
44
+ function runtimeFingerprint(module) {
45
+ return JSON.stringify({
46
+ code: module.code,
47
+ scopeId: module.scopeId,
48
+ hasScoped: module.hasScoped,
49
+ macroArtifacts: module.macroArtifacts?.map((artifact) => ({
50
+ kind: artifact.kind,
51
+ name: artifact.name,
52
+ source: artifact.source,
53
+ content: artifact.content,
54
+ moduleCode: artifact.moduleCode,
55
+ start: artifact.start,
56
+ end: artifact.end
57
+ })),
58
+ styles: module.styles?.map((style) => ({
59
+ lang: style.lang,
60
+ scoped: style.scoped,
61
+ module: style.module,
62
+ index: style.index
63
+ })),
64
+ dependencies: [...module.dependencies ?? []].sort()
65
+ });
66
+ }
67
+ function styleFingerprint(module) {
68
+ return JSON.stringify({
69
+ css: module.css,
70
+ styles: module.styles?.map((style) => ({
71
+ index: style.index,
72
+ content: style.content
73
+ }))
74
+ });
75
+ }
38
76
  //#endregion
39
77
  //#region src/utils/css.ts
40
78
  function scopeCssForPipeline(css, scopeId) {
@@ -282,7 +320,34 @@ function createLogger(debug) {
282
320
  error: (...args) => console.error("[vize]", ...args)
283
321
  };
284
322
  }
323
+ //#endregion
324
+ //#region src/config.ts
325
+ const require = createRequire(import.meta.url);
326
+ const CONFIG_FILE_NAMES = [
327
+ "vize.config.pkl",
328
+ "vize.config.ts",
329
+ "vize.config.js",
330
+ "vize.config.mjs",
331
+ "vize.config.json"
332
+ ];
333
+ let vizeConfigModulePromise = null;
334
+ function loadVizeConfigModule() {
335
+ vizeConfigModulePromise ??= import("vize/config");
336
+ return vizeConfigModulePromise;
337
+ }
338
+ function defineConfig(config) {
339
+ return config;
340
+ }
341
+ async function loadConfig(root, options) {
342
+ return (await loadVizeConfigModule()).loadConfig(root, options);
343
+ }
344
+ async function resolveConfigExport(exported, env) {
345
+ return (await loadVizeConfigModule()).resolveConfigExport(exported, env);
346
+ }
347
+ require.resolve("vize/schemas/vize.config.schema.json");
348
+ require.resolve("vize/pkl/vize.pkl");
285
349
  [...CONFIG_FILE_NAMES];
350
+ const VIZE_CONFIG_FILE_ENV = "VIZE_CONFIG_FILE";
286
351
  /**
287
352
  * Shared config store for inter-plugin communication.
288
353
  * Key = project root, Value = resolved VizeConfig.
@@ -394,12 +459,12 @@ function resolveSfcSrcImports(filePath, source) {
394
459
  dependencies
395
460
  };
396
461
  }
397
- function compileFile(filePath, cache, options, source) {
462
+ function compileFile(filePath, cache, options, source, diagnostics) {
398
463
  const resolved = resolveSfcSrcImports(filePath, source ?? fs.readFileSync(filePath, "utf-8"));
399
464
  const scopeId = generateScopeId(filePath);
400
465
  const result = compileSfc(resolved.source, buildCompileFileOptions(filePath, options));
401
466
  if (result.errors.length > 0) throw new VizeSfcCompileError(filePath, result.errors);
402
- if (result.warnings.length > 0) result.warnings.forEach((warning) => {
467
+ if (result.warnings.length > 0 && (diagnostics?.logWarnings ?? true)) result.warnings.forEach((warning) => {
403
468
  console.warn(`[vize] Warning in ${filePath}: ${warning}`);
404
469
  });
405
470
  const compiled = {
@@ -495,6 +560,9 @@ const DEFAULT_PRECOMPILE_IGNORE_PATTERNS = [
495
560
  ".nitro/**",
496
561
  "coverage/**"
497
562
  ];
563
+ function isPrecompileSfcPath(path) {
564
+ return path.endsWith(".vue");
565
+ }
498
566
  function diffPrecompileFiles(files, currentMetadata, previousMetadata) {
499
567
  return diffVitePrecompileFiles([...files], toNativePrecompileMetadataEntries(currentMetadata), toNativePrecompileMetadataEntries(previousMetadata));
500
568
  }
@@ -560,13 +628,13 @@ function clearBuildCaches(state) {
560
628
  */
561
629
  async function compileAll(state) {
562
630
  const startTime = performance.now();
563
- const files = await glob(state.scanPatterns, {
631
+ const sfcFiles = (await glob(state.scanPatterns, {
564
632
  cwd: state.root,
565
633
  ignore: state.ignorePatterns,
566
634
  absolute: true
567
- });
635
+ })).filter(isPrecompileSfcPath);
568
636
  const currentMetadata = /* @__PURE__ */ new Map();
569
- for (const file of files) try {
637
+ for (const file of sfcFiles) try {
570
638
  const stat = fs.statSync(file);
571
639
  currentMetadata.set(file, {
572
640
  mtimeMs: stat.mtimeMs,
@@ -575,8 +643,8 @@ async function compileAll(state) {
575
643
  } catch (e) {
576
644
  state.logger.error(`Failed to stat ${file}:`, e);
577
645
  }
578
- const { changedFiles, deletedFiles } = diffPrecompileFiles(files, currentMetadata, state.precompileMetadata);
579
- const cachedFileCount = files.length - changedFiles.length;
646
+ const { changedFiles, deletedFiles } = diffPrecompileFiles(sfcFiles, currentMetadata, state.precompileMetadata);
647
+ const cachedFileCount = sfcFiles.length - changedFiles.length;
580
648
  for (const file of deletedFiles) {
581
649
  state.cache.delete(file);
582
650
  state.ssrCache.delete(file);
@@ -584,7 +652,7 @@ async function compileAll(state) {
584
652
  state.precompileMetadata.delete(file);
585
653
  state.pendingHmrUpdateTypes.delete(file);
586
654
  }
587
- state.logger.info(`Pre-compiling ${files.length} Vue files... (${changedFiles.length} changed, ${cachedFileCount} cached, ${deletedFiles.length} removed)`);
655
+ state.logger.info(`Pre-compiling ${sfcFiles.length} Vue files... (${changedFiles.length} changed, ${cachedFileCount} cached, ${deletedFiles.length} removed)`);
588
656
  if (changedFiles.length === 0) {
589
657
  const elapsed = (performance.now() - startTime).toFixed(2);
590
658
  state.logger.info(`Pre-compilation complete: cache reused (${elapsed}ms)`);
@@ -1341,16 +1409,43 @@ async function resolveIdHook(ctx, state, id, importer, options) {
1341
1409
  return null;
1342
1410
  }
1343
1411
  //#endregion
1412
+ //#region src/plugin/load-sfc.ts
1413
+ function shouldLoadVueSfcRequest(request) {
1414
+ if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
1415
+ if (!request.querySuffix) return true;
1416
+ const params = new URLSearchParams(request.querySuffix.slice(1));
1417
+ if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
1418
+ return params.has("nuxt_component");
1419
+ }
1420
+ function getLoadableVueSfcPath(request) {
1421
+ if (!shouldLoadVueSfcRequest(request)) return null;
1422
+ return classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
1423
+ }
1424
+ function shouldLoadCompiledVueSfcPath(state, realPath, hasNuxtComponentQuery = false) {
1425
+ const isNodeModulesPath = realPath.includes("node_modules");
1426
+ if (!(state.mergedOptions.handleNodeModulesVue ?? true) && isNodeModulesPath && hasNuxtComponentQuery) {
1427
+ state.logger.log(`load: skipping node_modules Vue SFC ${realPath}`);
1428
+ return false;
1429
+ }
1430
+ if (!isNodeModulesPath && !state.filter(realPath)) {
1431
+ state.logger.log(`load: skipping filtered Vue SFC ${realPath}`);
1432
+ return false;
1433
+ }
1434
+ return true;
1435
+ }
1436
+ //#endregion
1344
1437
  //#region src/plugin/vite-transform.ts
1345
1438
  function createVirtualTypeScriptTransformer(viteApi) {
1346
1439
  return async (code, id) => {
1347
1440
  if (typeof viteApi.transformWithOxc === "function") return viteApi.transformWithOxc(code, id, {
1348
1441
  lang: "ts",
1349
- sourcemap: false
1442
+ sourcemap: false,
1443
+ target: "esnext"
1350
1444
  });
1351
1445
  if (typeof viteApi.transformWithEsbuild === "function") return viteApi.transformWithEsbuild(code, id, {
1352
1446
  loader: "ts",
1353
- sourcemap: false
1447
+ sourcemap: false,
1448
+ target: "esnext"
1354
1449
  });
1355
1450
  throw new Error("Installed Vite does not expose transformWithOxc or transformWithEsbuild");
1356
1451
  };
@@ -1405,17 +1500,6 @@ function findMacroArtifactModule(state, realPath, ssr, kind) {
1405
1500
  }, realPath, compiled);
1406
1501
  return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
1407
1502
  }
1408
- function shouldLoadVueSfcRequest(request) {
1409
- if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
1410
- if (!request.querySuffix) return true;
1411
- const params = new URLSearchParams(request.querySuffix.slice(1));
1412
- if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
1413
- return params.has("nuxt_component");
1414
- }
1415
- function getLoadableVueSfcPath(request) {
1416
- if (!shouldLoadVueSfcRequest(request)) return null;
1417
- return classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
1418
- }
1419
1503
  function normalizeStyleVirtualId(id) {
1420
1504
  const withoutPrefix = id.startsWith("\0") ? id.slice(1) : id;
1421
1505
  if (!withoutPrefix.includes("?vue")) return id;
@@ -1435,14 +1519,14 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
1435
1519
  let compiled = cache.get(realPath);
1436
1520
  if (!compiled && fs.existsSync(realPath)) {
1437
1521
  state.logger.log(`load: on-demand compiling ${realPath}`);
1438
- compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr));
1522
+ compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr), void 0, { logWarnings: shouldLogSfcWarnings(state, realPath) });
1439
1523
  }
1440
1524
  syncCollectedCssForFile({
1441
1525
  ...state,
1442
1526
  extractCss
1443
1527
  }, realPath, compiled);
1444
1528
  if (!compiled) return null;
1445
- for (const dependency of compiled.dependencies ?? []) loadOptions?.addWatchFile?.(dependency);
1529
+ for (const watchFile of new Set([realPath, ...compiled.dependencies ?? []])) loadOptions?.addWatchFile?.(watchFile);
1446
1530
  const hasDelegated = hasDelegatedStyles(compiled);
1447
1531
  const pendingHmrUpdateType = loadOptions?.ssr ? void 0 : state.pendingHmrUpdateTypes.get(realPath);
1448
1532
  if (compiled.css && !hasDelegated) compiled = {
@@ -1493,7 +1577,7 @@ function loadHook(state, id, loadOptions) {
1493
1577
  const realPath = sourceRequest.vizeVirtualPath ?? sourceRequest.normalizedFsId ?? sourceRequest.normalizedVuePath ?? styleRequest.path;
1494
1578
  const lang = styleRequest.styleLang ?? null;
1495
1579
  const scoped = styleRequest.styleScoped ?? null;
1496
- const fallbackCompiled = state.cache.get(realPath) ?? state.ssrCache.get(realPath);
1580
+ const fallbackCompiled = loadOptions?.ssr ? state.ssrCache.get(realPath) ?? state.cache.get(realPath) : state.cache.get(realPath) ?? state.ssrCache.get(realPath);
1497
1581
  const blockIndex = styleRequest.styleIndex ?? -1;
1498
1582
  if (fallbackCompiled?.styles && blockIndex >= 0 && blockIndex < fallbackCompiled.styles.length) {
1499
1583
  const block = fallbackCompiled.styles[blockIndex];
@@ -1531,9 +1615,13 @@ function loadHook(state, id, loadOptions) {
1531
1615
  state.logger.log(`load: skipping non-vue virtual module ${realPath}`);
1532
1616
  return null;
1533
1617
  }
1618
+ if (!shouldLoadCompiledVueSfcPath(state, realPath)) return null;
1534
1619
  return loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions);
1535
1620
  }
1536
- if (loadableVueSfcPath) return loadCompiledSfcModule(state, loadableVueSfcPath, !!loadOptions?.ssr, currentBase, loadOptions);
1621
+ if (loadableVueSfcPath) {
1622
+ if (!shouldLoadCompiledVueSfcPath(state, loadableVueSfcPath, !!request.querySuffix && new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component"))) return null;
1623
+ return loadCompiledSfcModule(state, loadableVueSfcPath, !!loadOptions?.ssr, currentBase, loadOptions);
1624
+ }
1537
1625
  if (id.startsWith("\0")) {
1538
1626
  const afterPrefix = id.startsWith("\0vize:") ? id.slice(6) : id.slice(1);
1539
1627
  if (afterPrefix.includes("?commonjs-")) return null;
@@ -1548,8 +1636,13 @@ function loadHook(state, id, loadOptions) {
1548
1636
  }
1549
1637
  return null;
1550
1638
  }
1639
+ function shouldLogSfcWarnings(state, realPath) {
1640
+ if (!realPath.includes("node_modules")) return true;
1641
+ if ((state.mergedOptions.handleNodeModulesVue ?? true) === false) return false;
1642
+ return state.filter(realPath);
1643
+ }
1551
1644
  function isJsxComponentPath(path) {
1552
- return path.endsWith(".jsx") || path.endsWith(".tsx");
1645
+ return /\.[jt]sx$/.test(path) && !/\.(?:stories|story)\.[jt]sx$/.test(path);
1553
1646
  }
1554
1647
  function shouldTransformJsxRequest(state, request) {
1555
1648
  if (!isJsxComponentPath(request.path)) return false;
@@ -1631,6 +1724,44 @@ function getVueFilesDependingOn(state, dependencyFile) {
1631
1724
  for (const cache of [state.cache, state.ssrCache]) for (const [vueFile, compiled] of cache) if (compiled.dependencies?.some((dependency) => path.resolve(dependency) === normalizedDependency)) owners.add(vueFile);
1632
1725
  return [...owners];
1633
1726
  }
1727
+ function unique(values) {
1728
+ return [...new Set(values)];
1729
+ }
1730
+ function toViteFsFileId(fileId) {
1731
+ if (!path.isAbsolute(fileId)) return null;
1732
+ const normalized = fileId.replace(/\\/g, "/");
1733
+ return normalized.startsWith("/") ? `/@fs${normalized}` : `/@fs/${normalized}`;
1734
+ }
1735
+ function getVueModuleFileCandidates(vueFile) {
1736
+ const candidates = [
1737
+ toVirtualId(vueFile),
1738
+ toPluginVisibleVirtualId(vueFile),
1739
+ toVirtualId(vueFile, true),
1740
+ toPluginVisibleVirtualId(vueFile, true),
1741
+ toPluginVisibleVirtualId(vueFile).split("?")[0],
1742
+ vueFile
1743
+ ];
1744
+ const viteFsCandidates = candidates.flatMap((candidate) => {
1745
+ const viteFsId = toViteFsFileId(candidate);
1746
+ return viteFsId ? [viteFsId] : [];
1747
+ });
1748
+ return unique([...candidates, ...viteFsCandidates]);
1749
+ }
1750
+ function getStyleModuleFileCandidates(styleId) {
1751
+ return unique([styleId, `${styleId}.css`]);
1752
+ }
1753
+ function collectModulesByFile(server, fileIds) {
1754
+ const modules = /* @__PURE__ */ new Set();
1755
+ for (const fileId of fileIds) {
1756
+ const matched = server.moduleGraph.getModulesByFile(fileId);
1757
+ if (!matched) continue;
1758
+ for (const mod of matched) modules.add(mod);
1759
+ }
1760
+ return modules;
1761
+ }
1762
+ function invalidateModules(server, modules) {
1763
+ for (const module of modules) server.moduleGraph.invalidateModule(module);
1764
+ }
1634
1765
  async function handleHotUpdateHook(state, ctx) {
1635
1766
  const { file, server, read } = ctx;
1636
1767
  const dependencyOwners = getVueFilesDependingOn(state, file);
@@ -1642,9 +1773,8 @@ async function handleHotUpdateHook(state, ctx) {
1642
1773
  state.collectedCss.delete(vueFile);
1643
1774
  state.precompileMetadata.delete(vueFile);
1644
1775
  state.pendingHmrUpdateTypes.set(vueFile, "full-reload");
1645
- const virtualId = toVirtualId(vueFile);
1646
- const modules = server.moduleGraph.getModulesByFile(virtualId) ?? server.moduleGraph.getModulesByFile(vueFile);
1647
- if (modules) for (const module of modules) {
1776
+ const modules = collectModulesByFile(server, getVueModuleFileCandidates(vueFile));
1777
+ for (const module of modules) {
1648
1778
  server.moduleGraph.invalidateModule(module);
1649
1779
  affectedModules.add(module);
1650
1780
  }
@@ -1674,8 +1804,7 @@ async function handleHotUpdateHook(state, ctx) {
1674
1804
  }
1675
1805
  const updateType = detectHmrUpdateType(prevCompiled, newCompiled);
1676
1806
  state.logger.log(`Re-compiled: ${path.relative(state.root, file)} (${updateType})`);
1677
- const virtualId = toVirtualId(file);
1678
- const modules = server.moduleGraph.getModulesByFile(virtualId) ?? server.moduleGraph.getModulesByFile(file);
1807
+ const modules = collectModulesByFile(server, getVueModuleFileCandidates(file));
1679
1808
  const hasDelegated = hasDelegatedStyles(newCompiled);
1680
1809
  if (hasDelegated && updateType === "style-only") {
1681
1810
  const affectedModules = /* @__PURE__ */ new Set();
@@ -1687,12 +1816,11 @@ async function handleHotUpdateHook(state, ctx) {
1687
1816
  if (block.scoped) params.set("scoped", `data-v-${newCompiled.scopeId}`);
1688
1817
  params.set("lang", block.lang ?? "css");
1689
1818
  if (block.module !== false) params.set("module", typeof block.module === "string" ? block.module : "");
1690
- const styleId = `${file}?${params.toString()}`;
1691
- const styleMods = server.moduleGraph.getModulesByFile(styleId);
1692
- if (styleMods) for (const mod of styleMods) affectedModules.add(mod);
1819
+ const styleMods = collectModulesByFile(server, getStyleModuleFileCandidates(`${file}?${params.toString()}`));
1820
+ for (const mod of styleMods) affectedModules.add(mod);
1693
1821
  }
1694
1822
  if (affectedModules.size > 0) return [...affectedModules];
1695
- if (modules) return [...modules];
1823
+ if (modules.size > 0) return [...modules];
1696
1824
  return [];
1697
1825
  }
1698
1826
  if (updateType === "style-only" && newCompiled.css && !hasDelegated) {
@@ -1708,8 +1836,9 @@ async function handleHotUpdateHook(state, ctx) {
1708
1836
  });
1709
1837
  return [];
1710
1838
  }
1711
- if (modules) {
1839
+ if (modules.size > 0) {
1712
1840
  state.pendingHmrUpdateTypes.set(file, updateType);
1841
+ invalidateModules(server, modules);
1713
1842
  return [...modules];
1714
1843
  }
1715
1844
  state.pendingHmrUpdateTypes.delete(file);
@@ -1953,7 +2082,7 @@ function installVirtualAssetMiddleware(devServer, state) {
1953
2082
  //#endregion
1954
2083
  //#region src/plugin/vue-version.ts
1955
2084
  function isLegacyVueVersion(version) {
1956
- return version === "legacy" || version === .11 || version === 1 || version === 2;
2085
+ return version === "legacy" || version === .11 || version === 1 || version === 2 || version === "2.7";
1957
2086
  }
1958
2087
  function isLegacyVueCompatibilityMode(options) {
1959
2088
  const vueVersion = options.vueVersion ?? options.compatibility?.vueVersion;
@@ -1968,10 +2097,7 @@ function createLegacyVueCompatibilityPlugin(options) {
1968
2097
  };
1969
2098
  }
1970
2099
  //#endregion
1971
- //#region src/plugin/index.ts
1972
- function aliasSortKey(find) {
1973
- return typeof find === "string" ? find.length : find.source.length;
1974
- }
2100
+ //#region src/plugin/shared-config.ts
1975
2101
  function mergeSharedConfig(baseConfig, overrideConfig) {
1976
2102
  if (!baseConfig) return overrideConfig;
1977
2103
  if (!overrideConfig) return baseConfig;
@@ -2013,6 +2139,11 @@ function mergeSharedConfig(baseConfig, overrideConfig) {
2013
2139
  entries: [...baseConfig.entries, ...overrideConfig.entries]
2014
2140
  };
2015
2141
  }
2142
+ //#endregion
2143
+ //#region src/plugin/index.ts
2144
+ function aliasSortKey(find) {
2145
+ return typeof find === "string" ? find.length : find.source.length;
2146
+ }
2016
2147
  function shouldExtractCssForBuild(state, context) {
2017
2148
  if (!state.isProduction) return false;
2018
2149
  const environmentName = context.environment?.name;
@@ -2098,15 +2229,18 @@ function vize(options = {}) {
2098
2229
  isSsrBuild: !!resolvedConfig.build?.ssr
2099
2230
  };
2100
2231
  let fileConfig = null;
2101
- if (options.configMode !== false) try {
2102
- fileConfig = await loadConfig(state.root, {
2103
- mode: options.configMode ?? "root",
2104
- configFile: options.configFile,
2105
- env: configEnv
2106
- });
2107
- if (fileConfig) state.logger.log("Loaded config from vize.config file");
2108
- } catch (error) {
2109
- state.logger.warn(`Failed to load vize config from ${options.configFile ?? state.root}:`, error);
2232
+ if (options.configMode !== false) {
2233
+ const configFile = options.configFile ?? process.env["VIZE_CONFIG_FILE"];
2234
+ try {
2235
+ fileConfig = await loadConfig(state.root, {
2236
+ mode: options.configMode ?? "root",
2237
+ configFile,
2238
+ env: configEnv
2239
+ });
2240
+ if (fileConfig) state.logger.log("Loaded config from vize.config file");
2241
+ } catch (error) {
2242
+ state.logger.warn(`Failed to load vize config from ${configFile ?? state.root}:`, error);
2243
+ }
2110
2244
  }
2111
2245
  let inlineConfig = null;
2112
2246
  if (options.config) try {
@@ -2223,4 +2357,4 @@ function vize(options = {}) {
2223
2357
  const __internal = { rewriteStaticAssetUrls };
2224
2358
  var src_default = vize;
2225
2359
  //#endregion
2226
- export { __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, src_default as default, defineConfig, loadConfig, resolveConfigExport, vize, vizeConfigStore };
2360
+ export { VIZE_CONFIG_FILE_ENV, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, src_default as default, defineConfig, loadConfig, resolveConfigExport, vize, vizeConfigStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.243.0",
3
+ "version": "0.263.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -40,9 +40,9 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@vizejs/native": "0.243.0",
43
+ "@vizejs/native": "0.263.0",
44
44
  "tinyglobby": "0.2.16",
45
- "vize": "0.243.0"
45
+ "vize": "0.263.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/node": "25.9.2",
@@ -51,7 +51,7 @@
51
51
  "vite-plus": "0.1.21"
52
52
  },
53
53
  "peerDependencies": {
54
- "vite": "^8.0.0"
54
+ "vite": "^7.3.0 || ^8.0.0"
55
55
  },
56
56
  "engines": {
57
57
  "node": ">=22"