@vizejs/vite-plugin 0.250.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,4 +1,3 @@
1
- import { defineConfig, loadConfig, resolveConfigExport } from "vize";
2
1
  import { Plugin } from "vite";
3
2
 
4
3
  //#region ../../cli/src/types/generated.d.ts
@@ -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";
@@ -321,7 +320,34 @@ function createLogger(debug) {
321
320
  error: (...args) => console.error("[vize]", ...args)
322
321
  };
323
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");
324
349
  [...CONFIG_FILE_NAMES];
350
+ const VIZE_CONFIG_FILE_ENV = "VIZE_CONFIG_FILE";
325
351
  /**
326
352
  * Shared config store for inter-plugin communication.
327
353
  * Key = project root, Value = resolved VizeConfig.
@@ -433,12 +459,12 @@ function resolveSfcSrcImports(filePath, source) {
433
459
  dependencies
434
460
  };
435
461
  }
436
- function compileFile(filePath, cache, options, source) {
462
+ function compileFile(filePath, cache, options, source, diagnostics) {
437
463
  const resolved = resolveSfcSrcImports(filePath, source ?? fs.readFileSync(filePath, "utf-8"));
438
464
  const scopeId = generateScopeId(filePath);
439
465
  const result = compileSfc(resolved.source, buildCompileFileOptions(filePath, options));
440
466
  if (result.errors.length > 0) throw new VizeSfcCompileError(filePath, result.errors);
441
- if (result.warnings.length > 0) result.warnings.forEach((warning) => {
467
+ if (result.warnings.length > 0 && (diagnostics?.logWarnings ?? true)) result.warnings.forEach((warning) => {
442
468
  console.warn(`[vize] Warning in ${filePath}: ${warning}`);
443
469
  });
444
470
  const compiled = {
@@ -1383,16 +1409,43 @@ async function resolveIdHook(ctx, state, id, importer, options) {
1383
1409
  return null;
1384
1410
  }
1385
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
1386
1437
  //#region src/plugin/vite-transform.ts
1387
1438
  function createVirtualTypeScriptTransformer(viteApi) {
1388
1439
  return async (code, id) => {
1389
1440
  if (typeof viteApi.transformWithOxc === "function") return viteApi.transformWithOxc(code, id, {
1390
1441
  lang: "ts",
1391
- sourcemap: false
1442
+ sourcemap: false,
1443
+ target: "esnext"
1392
1444
  });
1393
1445
  if (typeof viteApi.transformWithEsbuild === "function") return viteApi.transformWithEsbuild(code, id, {
1394
1446
  loader: "ts",
1395
- sourcemap: false
1447
+ sourcemap: false,
1448
+ target: "esnext"
1396
1449
  });
1397
1450
  throw new Error("Installed Vite does not expose transformWithOxc or transformWithEsbuild");
1398
1451
  };
@@ -1447,17 +1500,6 @@ function findMacroArtifactModule(state, realPath, ssr, kind) {
1447
1500
  }, realPath, compiled);
1448
1501
  return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
1449
1502
  }
1450
- function shouldLoadVueSfcRequest(request) {
1451
- if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
1452
- if (!request.querySuffix) return true;
1453
- const params = new URLSearchParams(request.querySuffix.slice(1));
1454
- if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
1455
- return params.has("nuxt_component");
1456
- }
1457
- function getLoadableVueSfcPath(request) {
1458
- if (!shouldLoadVueSfcRequest(request)) return null;
1459
- return classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
1460
- }
1461
1503
  function normalizeStyleVirtualId(id) {
1462
1504
  const withoutPrefix = id.startsWith("\0") ? id.slice(1) : id;
1463
1505
  if (!withoutPrefix.includes("?vue")) return id;
@@ -1477,14 +1519,14 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
1477
1519
  let compiled = cache.get(realPath);
1478
1520
  if (!compiled && fs.existsSync(realPath)) {
1479
1521
  state.logger.log(`load: on-demand compiling ${realPath}`);
1480
- compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr));
1522
+ compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr), void 0, { logWarnings: shouldLogSfcWarnings(state, realPath) });
1481
1523
  }
1482
1524
  syncCollectedCssForFile({
1483
1525
  ...state,
1484
1526
  extractCss
1485
1527
  }, realPath, compiled);
1486
1528
  if (!compiled) return null;
1487
- for (const dependency of compiled.dependencies ?? []) loadOptions?.addWatchFile?.(dependency);
1529
+ for (const watchFile of new Set([realPath, ...compiled.dependencies ?? []])) loadOptions?.addWatchFile?.(watchFile);
1488
1530
  const hasDelegated = hasDelegatedStyles(compiled);
1489
1531
  const pendingHmrUpdateType = loadOptions?.ssr ? void 0 : state.pendingHmrUpdateTypes.get(realPath);
1490
1532
  if (compiled.css && !hasDelegated) compiled = {
@@ -1535,7 +1577,7 @@ function loadHook(state, id, loadOptions) {
1535
1577
  const realPath = sourceRequest.vizeVirtualPath ?? sourceRequest.normalizedFsId ?? sourceRequest.normalizedVuePath ?? styleRequest.path;
1536
1578
  const lang = styleRequest.styleLang ?? null;
1537
1579
  const scoped = styleRequest.styleScoped ?? null;
1538
- 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);
1539
1581
  const blockIndex = styleRequest.styleIndex ?? -1;
1540
1582
  if (fallbackCompiled?.styles && blockIndex >= 0 && blockIndex < fallbackCompiled.styles.length) {
1541
1583
  const block = fallbackCompiled.styles[blockIndex];
@@ -1573,9 +1615,13 @@ function loadHook(state, id, loadOptions) {
1573
1615
  state.logger.log(`load: skipping non-vue virtual module ${realPath}`);
1574
1616
  return null;
1575
1617
  }
1618
+ if (!shouldLoadCompiledVueSfcPath(state, realPath)) return null;
1576
1619
  return loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions);
1577
1620
  }
1578
- 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
+ }
1579
1625
  if (id.startsWith("\0")) {
1580
1626
  const afterPrefix = id.startsWith("\0vize:") ? id.slice(6) : id.slice(1);
1581
1627
  if (afterPrefix.includes("?commonjs-")) return null;
@@ -1590,8 +1636,13 @@ function loadHook(state, id, loadOptions) {
1590
1636
  }
1591
1637
  return null;
1592
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
+ }
1593
1644
  function isJsxComponentPath(path) {
1594
- return path.endsWith(".jsx") || path.endsWith(".tsx");
1645
+ return /\.[jt]sx$/.test(path) && !/\.(?:stories|story)\.[jt]sx$/.test(path);
1595
1646
  }
1596
1647
  function shouldTransformJsxRequest(state, request) {
1597
1648
  if (!isJsxComponentPath(request.path)) return false;
@@ -1676,15 +1727,25 @@ function getVueFilesDependingOn(state, dependencyFile) {
1676
1727
  function unique(values) {
1677
1728
  return [...new Set(values)];
1678
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
+ }
1679
1735
  function getVueModuleFileCandidates(vueFile) {
1680
- return unique([
1736
+ const candidates = [
1681
1737
  toVirtualId(vueFile),
1682
1738
  toPluginVisibleVirtualId(vueFile),
1683
1739
  toVirtualId(vueFile, true),
1684
1740
  toPluginVisibleVirtualId(vueFile, true),
1685
1741
  toPluginVisibleVirtualId(vueFile).split("?")[0],
1686
1742
  vueFile
1687
- ]);
1743
+ ];
1744
+ const viteFsCandidates = candidates.flatMap((candidate) => {
1745
+ const viteFsId = toViteFsFileId(candidate);
1746
+ return viteFsId ? [viteFsId] : [];
1747
+ });
1748
+ return unique([...candidates, ...viteFsCandidates]);
1688
1749
  }
1689
1750
  function getStyleModuleFileCandidates(styleId) {
1690
1751
  return unique([styleId, `${styleId}.css`]);
@@ -2021,7 +2082,7 @@ function installVirtualAssetMiddleware(devServer, state) {
2021
2082
  //#endregion
2022
2083
  //#region src/plugin/vue-version.ts
2023
2084
  function isLegacyVueVersion(version) {
2024
- return version === "legacy" || version === .11 || version === 1 || version === 2;
2085
+ return version === "legacy" || version === .11 || version === 1 || version === 2 || version === "2.7";
2025
2086
  }
2026
2087
  function isLegacyVueCompatibilityMode(options) {
2027
2088
  const vueVersion = options.vueVersion ?? options.compatibility?.vueVersion;
@@ -2036,10 +2097,7 @@ function createLegacyVueCompatibilityPlugin(options) {
2036
2097
  };
2037
2098
  }
2038
2099
  //#endregion
2039
- //#region src/plugin/index.ts
2040
- function aliasSortKey(find) {
2041
- return typeof find === "string" ? find.length : find.source.length;
2042
- }
2100
+ //#region src/plugin/shared-config.ts
2043
2101
  function mergeSharedConfig(baseConfig, overrideConfig) {
2044
2102
  if (!baseConfig) return overrideConfig;
2045
2103
  if (!overrideConfig) return baseConfig;
@@ -2081,6 +2139,11 @@ function mergeSharedConfig(baseConfig, overrideConfig) {
2081
2139
  entries: [...baseConfig.entries, ...overrideConfig.entries]
2082
2140
  };
2083
2141
  }
2142
+ //#endregion
2143
+ //#region src/plugin/index.ts
2144
+ function aliasSortKey(find) {
2145
+ return typeof find === "string" ? find.length : find.source.length;
2146
+ }
2084
2147
  function shouldExtractCssForBuild(state, context) {
2085
2148
  if (!state.isProduction) return false;
2086
2149
  const environmentName = context.environment?.name;
@@ -2166,15 +2229,18 @@ function vize(options = {}) {
2166
2229
  isSsrBuild: !!resolvedConfig.build?.ssr
2167
2230
  };
2168
2231
  let fileConfig = null;
2169
- if (options.configMode !== false) try {
2170
- fileConfig = await loadConfig(state.root, {
2171
- mode: options.configMode ?? "root",
2172
- configFile: options.configFile,
2173
- env: configEnv
2174
- });
2175
- if (fileConfig) state.logger.log("Loaded config from vize.config file");
2176
- } catch (error) {
2177
- 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
+ }
2178
2244
  }
2179
2245
  let inlineConfig = null;
2180
2246
  if (options.config) try {
@@ -2291,4 +2357,4 @@ function vize(options = {}) {
2291
2357
  const __internal = { rewriteStaticAssetUrls };
2292
2358
  var src_default = vize;
2293
2359
  //#endregion
2294
- 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.250.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.251.0",
43
+ "@vizejs/native": "0.263.0",
44
44
  "tinyglobby": "0.2.16",
45
- "vize": "0.251.0"
45
+ "vize": "0.263.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/node": "25.9.2",