@vizejs/vite-plugin 0.96.0 → 0.100.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
@@ -546,6 +546,7 @@ interface VizeOptions {
546
546
  root?: string;
547
547
  /**
548
548
  * Glob patterns to scan for .vue files during pre-compilation
549
+ * Use an empty array to disable startup pre-compilation and compile on demand.
549
550
  * @default ['**\/*.vue']
550
551
  */
551
552
  scanPatterns?: string[];
package/dist/index.mjs CHANGED
@@ -2,10 +2,10 @@ import { createRequire } from "node:module";
2
2
  import fs from "node:fs";
3
3
  import { createHash } from "node:crypto";
4
4
  import path from "node:path";
5
- import { CONFIG_FILE_NAMES, defineConfig, loadConfig } from "vize";
6
- import { glob } from "tinyglobby";
7
5
  import * as native from "@vizejs/native";
8
6
  import { classifyVitePluginRequest } from "@vizejs/native";
7
+ import { CONFIG_FILE_NAMES, defineConfig, loadConfig } from "vize";
8
+ import { glob } from "tinyglobby";
9
9
  import { pathToFileURL } from "node:url";
10
10
  import { transformWithOxc } from "vite";
11
11
  //#region src/hmr.ts
@@ -508,11 +508,11 @@ ${output}`;
508
508
  }
509
509
  return output;
510
510
  }
511
- const VIZE_SSR_PREFIX = "\0vize-ssr:";
511
+ const VIZE_SSR_PREFIX$1 = "\0vize-ssr:";
512
512
  const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
513
513
  /** Create a virtual module ID from a real .vue file path */
514
514
  function toVirtualId(realPath, ssr = false) {
515
- return ssr ? `${VIZE_SSR_PREFIX}${realPath}.ts` : "\0" + realPath + ".ts";
515
+ return ssr ? `${VIZE_SSR_PREFIX$1}${realPath}.ts` : "\0" + realPath + ".ts";
516
516
  }
517
517
  function escapeRegExp(value) {
518
518
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -688,10 +688,7 @@ function compileFile(filePath, cache, options, source) {
688
688
  * Returns per-file results with content hashes for HMR.
689
689
  */
690
690
  function compileBatch(files, cache, options) {
691
- const result = compileSfcBatchWithResults(files.map((f) => ({
692
- path: f.path,
693
- source: f.source
694
- })), buildCompileBatchOptions(options));
691
+ const result = compileSfcBatchWithResults(files, buildCompileBatchOptions(options));
695
692
  for (const fileResult of result.results) {
696
693
  if (fileResult.errors.length === 0) cache.set(fileResult.path, {
697
694
  code: fileResult.code,
@@ -741,10 +738,23 @@ function normalizePrecompileBatchSize(value) {
741
738
  if (value === void 0 || !Number.isFinite(value) || value <= 0) return 128;
742
739
  return Math.max(1, Math.floor(value));
743
740
  }
744
- function chunkPrecompileFiles(files, batchSize) {
741
+ function chunkPrecompileFiles(files, batchSize, options = {}) {
745
742
  const normalizedBatchSize = normalizePrecompileBatchSize(batchSize);
743
+ const maxBytes = Math.max(1, Math.floor(options.maxBytes ?? 33554432));
746
744
  const chunks = [];
747
- for (let start = 0; start < files.length; start += normalizedBatchSize) chunks.push(files.slice(start, start + normalizedBatchSize));
745
+ let current = [];
746
+ let currentBytes = 0;
747
+ for (const file of files) {
748
+ const fileBytes = Math.max(0, options.metadata?.get(file)?.size ?? 0);
749
+ if (current.length > 0 && (current.length >= normalizedBatchSize || currentBytes + fileBytes > maxBytes)) {
750
+ chunks.push(current);
751
+ current = [];
752
+ currentBytes = 0;
753
+ }
754
+ current.push(file);
755
+ currentBytes += fileBytes;
756
+ }
757
+ if (current.length > 0) chunks.push(current);
748
758
  return chunks;
749
759
  }
750
760
  function getEnvironmentCache(state, ssr) {
@@ -805,7 +815,7 @@ async function compileAll(state) {
805
815
  let successCount = 0;
806
816
  let failedCount = 0;
807
817
  let nativeTimeMs = 0;
808
- const chunks = chunkPrecompileFiles(changedFiles, state.precompileBatchSize);
818
+ const chunks = chunkPrecompileFiles(changedFiles, state.precompileBatchSize, { metadata: currentMetadata });
809
819
  for (const chunk of chunks) {
810
820
  const fileContents = [];
811
821
  for (const file of chunk) try {
@@ -1215,7 +1225,11 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
1215
1225
  function loadHook(state, id, loadOptions) {
1216
1226
  const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
1217
1227
  const request = classifyVitePluginRequest(id);
1218
- if (id === "\0vize:all-styles.css") return Array.from(state.collectedCss.values()).join("\n\n");
1228
+ if (id === "\0vize:all-styles.css") {
1229
+ let allCss = "";
1230
+ for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
1231
+ return allCss;
1232
+ }
1219
1233
  let styleId = id;
1220
1234
  if (id.startsWith("\0") && id.includes("?vue")) styleId = id.slice(1).replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
1221
1235
  const styleRequest = classifyVitePluginRequest(styleId);
@@ -1429,7 +1443,8 @@ async function handleHotUpdateHook(state, ctx) {
1429
1443
  }
1430
1444
  function handleGenerateBundleHook(state, emitFile) {
1431
1445
  if (!state.extractCss || state.collectedCss.size === 0) return;
1432
- const allCss = Array.from(state.collectedCss.values()).join("\n\n");
1446
+ let allCss = "";
1447
+ for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
1433
1448
  if (allCss.trim()) {
1434
1449
  emitFile({
1435
1450
  type: "asset",
@@ -1505,9 +1520,10 @@ function createPostTransformPlugin(state) {
1505
1520
  //#endregion
1506
1521
  //#region src/plugin/unocss.ts
1507
1522
  const bridgePatched = Symbol("vize.unocssBridgePatched");
1523
+ const VIZE_SSR_PREFIX = "\0vize-ssr:";
1508
1524
  const plainSsrPrefix = VIZE_SSR_PREFIX.slice(1);
1509
1525
  function stripBridgePrefix(id) {
1510
- if (id.startsWith("\0vize-ssr:")) return id.slice(10);
1526
+ if (id.startsWith(VIZE_SSR_PREFIX)) return id.slice(10);
1511
1527
  if (id.startsWith(plainSsrPrefix)) return id.slice(plainSsrPrefix.length);
1512
1528
  if (id.startsWith("\0")) return id.slice(1);
1513
1529
  return id;
@@ -1518,6 +1534,20 @@ function isUnoCssBridgeModuleId(id) {
1518
1534
  function normalizeUnoCssBridgeModuleId(id) {
1519
1535
  return stripBridgePrefix(id).replace(/\.ts(?=\?|$)/, "");
1520
1536
  }
1537
+ function appendOriginalVueSourceForUnoCss(code, normalizedId) {
1538
+ const sourcePath = normalizedId.split("?")[0];
1539
+ if (!sourcePath) return code;
1540
+ try {
1541
+ if (fs.statSync(sourcePath).size > 2097152) return code;
1542
+ } catch {
1543
+ return code;
1544
+ }
1545
+ try {
1546
+ return `${code}\n${fs.readFileSync(sourcePath, "utf-8")}`;
1547
+ } catch {
1548
+ return code;
1549
+ }
1550
+ }
1521
1551
  function patchUnoCssBridge(plugins) {
1522
1552
  for (const plugin of plugins) {
1523
1553
  if (!plugin.name?.startsWith("unocss:") || typeof plugin.transform !== "function" || plugin[bridgePatched]) continue;
@@ -1527,9 +1557,7 @@ function patchUnoCssBridge(plugins) {
1527
1557
  if (!isUnoCssBridgeModuleId(id)) return originalTransform.call(this, code, id, ...args);
1528
1558
  const normalizedId = normalizeUnoCssBridgeModuleId(id);
1529
1559
  let effectiveCode = code;
1530
- if (isExtractionOnly) try {
1531
- effectiveCode = `${code}\n${fs.readFileSync(normalizedId.split("?")[0], "utf-8")}`;
1532
- } catch {}
1560
+ if (isExtractionOnly) effectiveCode = appendOriginalVueSourceForUnoCss(code, normalizedId);
1533
1561
  return originalTransform.call(this, effectiveCode, normalizedId, ...args);
1534
1562
  };
1535
1563
  plugin[bridgePatched] = true;
@@ -1693,7 +1721,7 @@ function vize(options = {}) {
1693
1721
  });
1694
1722
  },
1695
1723
  async buildStart() {
1696
- if (!state.scanPatterns) return;
1724
+ if (!state.scanPatterns || state.scanPatterns.length === 0) return;
1697
1725
  await compileAll(state);
1698
1726
  state.logger.log("Cache keys:", [...state.cache.keys()].slice(0, 3));
1699
1727
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.96.0",
3
+ "version": "0.100.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -33,9 +33,9 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@vizejs/native": "0.96.0",
36
+ "@vizejs/native": "0.100.0",
37
37
  "tinyglobby": "0.2.16",
38
- "vize": "0.96.0"
38
+ "vize": "0.100.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "25.7.0",