@vizejs/vite-plugin 0.32.0 → 0.34.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
@@ -29,16 +29,16 @@ yarn add @vizejs/vite-plugin
29
29
 
30
30
  ```ts
31
31
  // vite.config.ts
32
- import { defineConfig } from 'vite'
33
- import vize from '@vizejs/vite-plugin'
32
+ import { defineConfig } from "vite";
33
+ import vize from "@vizejs/vite-plugin";
34
34
 
35
35
  export default defineConfig({
36
36
  plugins: [
37
37
  vize({
38
38
  // options
39
- })
40
- ]
41
- })
39
+ }),
40
+ ],
41
+ });
42
42
  ```
43
43
 
44
44
  ### Nuxt
@@ -47,23 +47,23 @@ For Nuxt 3, add the plugin to your `nuxt.config.ts`:
47
47
 
48
48
  ```ts
49
49
  // nuxt.config.ts
50
- import vize from '@vizejs/vite-plugin'
50
+ import vize from "@vizejs/vite-plugin";
51
51
 
52
52
  export default defineNuxtConfig({
53
53
  vite: {
54
54
  plugins: [
55
55
  vize({
56
56
  // Exclude Nuxt's internal .vue files if needed
57
- exclude: [/node_modules/, /#/, /\.nuxt/]
58
- })
59
- ]
57
+ exclude: [/node_modules/, /#/, /\.nuxt/],
58
+ }),
59
+ ],
60
60
  },
61
61
 
62
62
  // Disable the default Vue plugin
63
63
  vue: {
64
- propsDestructure: false
65
- }
66
- })
64
+ propsDestructure: false,
65
+ },
66
+ });
67
67
  ```
68
68
 
69
69
  **Note**: When using with Nuxt, you may need to disable Nuxt's built-in Vue plugin to avoid conflicts:
@@ -72,19 +72,17 @@ export default defineNuxtConfig({
72
72
  // nuxt.config.ts
73
73
  export default defineNuxtConfig({
74
74
  hooks: {
75
- 'vite:extendConfig': (config) => {
75
+ "vite:extendConfig": (config) => {
76
76
  // Remove @vitejs/plugin-vue from plugins
77
77
  config.plugins = config.plugins?.filter(
78
- (p) => p && (Array.isArray(p) ? p[0] : p).name !== 'vite:vue'
79
- )
80
- }
78
+ (p) => p && (Array.isArray(p) ? p[0] : p).name !== "vite:vue",
79
+ );
80
+ },
81
81
  },
82
82
  vite: {
83
- plugins: [
84
- vize()
85
- ]
86
- }
87
- })
83
+ plugins: [vize()],
84
+ },
85
+ });
88
86
  ```
89
87
 
90
88
  ## Options
@@ -95,55 +93,55 @@ interface VizeNativeOptions {
95
93
  * Files to include in compilation
96
94
  * @default /\.vue$/
97
95
  */
98
- include?: string | RegExp | (string | RegExp)[]
96
+ include?: string | RegExp | (string | RegExp)[];
99
97
 
100
98
  /**
101
99
  * Files to exclude from compilation
102
100
  * @default /node_modules/
103
101
  */
104
- exclude?: string | RegExp | (string | RegExp)[]
102
+ exclude?: string | RegExp | (string | RegExp)[];
105
103
 
106
104
  /**
107
105
  * Force production mode
108
106
  * @default auto-detected from Vite config
109
107
  */
110
- isProduction?: boolean
108
+ isProduction?: boolean;
111
109
 
112
110
  /**
113
111
  * Enable SSR mode
114
112
  * @default false
115
113
  */
116
- ssr?: boolean
114
+ ssr?: boolean;
117
115
 
118
116
  /**
119
117
  * Enable source map generation
120
118
  * @default true in development, false in production
121
119
  */
122
- sourceMap?: boolean
120
+ sourceMap?: boolean;
123
121
 
124
122
  /**
125
123
  * Enable Vapor mode compilation
126
124
  * @default false
127
125
  */
128
- vapor?: boolean
126
+ vapor?: boolean;
129
127
 
130
128
  /**
131
129
  * Root directory to scan for .vue files
132
130
  * @default Vite's root
133
131
  */
134
- root?: string
132
+ root?: string;
135
133
 
136
134
  /**
137
135
  * Glob patterns to scan for .vue files during pre-compilation
138
136
  * @default ['**\/*.vue']
139
137
  */
140
- scanPatterns?: string[]
138
+ scanPatterns?: string[];
141
139
 
142
140
  /**
143
141
  * Glob patterns to ignore during pre-compilation
144
142
  * @default ['node_modules/**', 'dist/**', '.git/**']
145
143
  */
146
- ignorePatterns?: string[]
144
+ ignorePatterns?: string[];
147
145
  }
148
146
  ```
149
147
 
@@ -180,26 +178,28 @@ When a `.vue` file changes:
180
178
 
181
179
  Vize's native compiler is significantly faster than the official Vue compiler:
182
180
 
183
- | Benchmark (15,000 SFCs) | @vue/compiler-sfc | Vize | Speedup |
184
- |-------------------------|-------------------|------|---------|
185
- | Single-threaded | 16.21s | 6.65s | **2.4x** |
186
- | Multi-threaded | 4.13s | 498ms | **8.3x** |
181
+ | Benchmark (15,000 SFCs) | @vue/compiler-sfc | Vize | Speedup |
182
+ | ----------------------- | ----------------- | ----- | -------- |
183
+ | Single-threaded | 16.21s | 6.65s | **2.4x** |
184
+ | Multi-threaded | 4.13s | 498ms | **8.3x** |
187
185
 
188
186
  ## Comparison with vite-plugin-vize
189
187
 
190
- | Feature | vite-plugin-vize | vite-plugin-vize |
191
- |---------|------------------|-------------------------|
192
- | Compiler | WASM | Native (NAPI) |
193
- | Pre-compilation | No | Yes |
194
- | Module Loading | Transform | Virtual Module (Load) |
195
- | Performance | Fast | Fastest |
196
- | Platform | Any | Node.js only |
188
+ | Feature | vite-plugin-vize | vite-plugin-vize |
189
+ | --------------- | ---------------- | --------------------- |
190
+ | Compiler | WASM | Native (NAPI) |
191
+ | Pre-compilation | No | Yes |
192
+ | Module Loading | Transform | Virtual Module (Load) |
193
+ | Performance | Fast | Fastest |
194
+ | Platform | Any | Node.js only |
197
195
 
198
196
  Use `vite-plugin-vize` (WASM-based) when you need:
197
+
199
198
  - Browser compatibility (e.g., StackBlitz, WebContainers)
200
199
  - Platform-independent deployment
201
200
 
202
201
  Use `vite-plugin-vize` when you need:
202
+
203
203
  - Maximum performance
204
204
  - Server-side only (standard Node.js environment)
205
205
 
@@ -1,9 +1,6 @@
1
1
  import { Plugin } from "vite";
2
2
 
3
3
  //#region ../vize/src/types/compiler.d.ts
4
- /**
5
- * Compiler configuration
6
- */
7
4
  /**
8
5
  * Compiler configuration
9
6
  */
@@ -88,7 +85,8 @@ interface VitePluginConfig {
88
85
  * @default ['node_modules/**', 'dist/**', '.git/**']
89
86
  */
90
87
  ignorePatterns?: string[];
91
- } //#endregion
88
+ }
89
+ //#endregion
92
90
  //#region ../vize/src/types/tools.d.ts
93
91
  /**
94
92
  * Linter configuration
@@ -225,7 +223,8 @@ interface LspConfig {
225
223
  * @default false
226
224
  */
227
225
  tsgo?: boolean;
228
- } //#endregion
226
+ }
227
+ //#endregion
229
228
  //#region ../vize/src/types/musea.d.ts
230
229
  /**
231
230
  * VRT (Visual Regression Testing) configuration for Musea
@@ -320,7 +319,8 @@ interface MuseaConfig {
320
319
  * Autogen configuration
321
320
  */
322
321
  autogen?: MuseaAutogenConfig;
323
- } //#endregion
322
+ }
323
+ //#endregion
324
324
  //#region ../vize/src/types/loader.d.ts
325
325
  /**
326
326
  * Global type declaration
@@ -360,7 +360,6 @@ interface LoadConfigOptions {
360
360
  */
361
361
  env?: ConfigEnv;
362
362
  }
363
-
364
363
  //#endregion
365
364
  //#region ../vize/src/types/core.d.ts
366
365
  type MaybePromise<T> = T | Promise<T>;
@@ -409,7 +408,6 @@ interface VizeConfig {
409
408
  */
410
409
  globalTypes?: GlobalTypesConfig;
411
410
  }
412
-
413
411
  //#endregion
414
412
  //#region src/types.d.ts
415
413
  interface VizeOptions {
@@ -512,23 +510,18 @@ interface CompiledModule {
512
510
  /** Per-block style metadata extracted from the source SFC */
513
511
  styles?: StyleBlockInfo[];
514
512
  }
515
-
516
513
  //#endregion
517
514
  //#region src/virtual.d.ts
518
515
  interface DynamicImportAliasRule {
519
516
  fromPrefix: string;
520
517
  toPrefix: string;
521
518
  }
522
-
523
519
  //#endregion
524
520
  //#region src/transform.d.ts
525
- /** Check if a module ID is a vize-compiled virtual module */
526
521
  declare function rewriteStaticAssetUrls(code: string, aliasRules: DynamicImportAliasRule[]): string;
527
-
528
522
  //#endregion
529
523
  //#region src/plugin/index.d.ts
530
524
  declare function vize(options?: VizeOptions): Plugin[];
531
-
532
525
  //#endregion
533
526
  //#region src/config.d.ts
534
527
  /**
@@ -546,12 +539,10 @@ declare function loadConfig(root: string, options?: LoadConfigOptions): Promise<
546
539
  * Used by musea() and other plugins to access the unified config.
547
540
  */
548
541
  declare const vizeConfigStore: Map<string, VizeConfig>;
549
-
550
542
  //#endregion
551
543
  //#region src/index.d.ts
552
544
  declare const __internal: {
553
545
  rewriteStaticAssetUrls: typeof rewriteStaticAssetUrls;
554
546
  };
555
-
556
547
  //#endregion
557
- export { CompiledModule, LoadConfigOptions, VizeConfig, VizeOptions, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, defineConfig, loadConfig, vize, vizeConfigStore };
548
+ export { type CompiledModule, type LoadConfigOptions, type VizeConfig, type VizeOptions, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, vizeConfigStore };
@@ -1,12 +1,11 @@
1
+ import { createRequire } from "node:module";
1
2
  import fs from "node:fs";
2
3
  import { createHash } from "node:crypto";
3
4
  import path from "node:path";
4
5
  import { glob } from "tinyglobby";
5
6
  import * as native from "@vizejs/native";
6
- import { createRequire } from "node:module";
7
7
  import { pathToFileURL } from "node:url";
8
8
  import { transformWithOxc } from "vite";
9
-
10
9
  //#region src/hmr.ts
11
10
  function didHashChange(prevHash, nextHash) {
12
11
  return prevHash !== nextHash;
@@ -24,11 +23,9 @@ function hasHmrChanges(prev, next) {
24
23
  */
25
24
  function detectHmrUpdateType(prev, next) {
26
25
  if (!prev) return "full-reload";
27
- const scriptChanged = didHashChange(prev.scriptHash, next.scriptHash);
28
- if (scriptChanged) return "full-reload";
26
+ if (didHashChange(prev.scriptHash, next.scriptHash)) return "full-reload";
29
27
  const templateChanged = didHashChange(prev.templateHash, next.templateHash);
30
- const styleChanged = didHashChange(prev.styleHash, next.styleHash);
31
- if (styleChanged && !templateChanged) return "style-only";
28
+ if (didHashChange(prev.styleHash, next.styleHash) && !templateChanged) return "style-only";
32
29
  if (templateChanged) return "template-only";
33
30
  return "full-reload";
34
31
  }
@@ -72,7 +69,6 @@ if (import.meta.hot) {
72
69
  }
73
70
  }`;
74
71
  }
75
-
76
72
  //#endregion
77
73
  //#region src/utils/css.ts
78
74
  /**
@@ -83,7 +79,7 @@ if (import.meta.hot) {
83
79
  * document.createElement('style'), bypassing Vite's CSS pipeline.
84
80
  */
85
81
  function resolveCssImports(css, importer, aliasRules, isDev, devUrlBase) {
86
- const customMedia = new Map();
82
+ const customMedia = /* @__PURE__ */ new Map();
87
83
  const importRegex = /^@import\s+(?:"([^"]+)"|'([^']+)');?\s*$/gm;
88
84
  let result = css;
89
85
  result = result.replace(importRegex, (_match, dqPath, sqPath) => {
@@ -112,8 +108,7 @@ function resolveCssImports(css, importer, aliasRules, isDev, devUrlBase) {
112
108
  if (resolved && fs.existsSync(resolved)) {
113
109
  const normalized = resolved.replace(/\\/g, "/");
114
110
  const base = devUrlBase ?? "/";
115
- const prefix = base.endsWith("/") ? base : base + "/";
116
- return `url("${prefix}@fs${normalized}")`;
111
+ return `url("${base.endsWith("/") ? base : base + "/"}@fs${normalized}")`;
117
112
  }
118
113
  return _match;
119
114
  });
@@ -138,7 +133,6 @@ function resolveCssPath(importPath, importer, aliasRules) {
138
133
  if (path.isAbsolute(importPath)) return importPath;
139
134
  return null;
140
135
  }
141
-
142
136
  //#endregion
143
137
  //#region src/utils/index.ts
144
138
  /** Known CSS preprocessor languages that must be delegated to Vite */
@@ -169,8 +163,7 @@ function supportsTemplateOnlyHmr(output) {
169
163
  return /(?:^|\n)(?:_sfc_main|__sfc__)\.render\s*=\s*render\b/m.test(output);
170
164
  }
171
165
  function generateScopeId(filename) {
172
- const hash = createHash("sha256").update(filename).digest("hex");
173
- return hash.slice(0, 8);
166
+ return createHash("sha256").update(filename).digest("hex").slice(0, 8);
174
167
  }
175
168
  function createFilter(include, exclude) {
176
169
  const includePatterns = include ? Array.isArray(include) ? include : [include] : [/\.vue$/];
@@ -206,8 +199,7 @@ function generateOutput(compiled, options) {
206
199
  output += "\n_sfc_main.ssrRender = ssrRender;";
207
200
  output += "\nexport default _sfc_main;";
208
201
  }
209
- const useDelegatedStyles = hasDelegatedStyles(compiled) && filePath;
210
- if (useDelegatedStyles) {
202
+ if (hasDelegatedStyles(compiled) && filePath) {
211
203
  const styleImports = [];
212
204
  const cssModuleImports = [];
213
205
  for (const block of compiled.styles) {
@@ -242,12 +234,9 @@ function generateOutput(compiled, options) {
242
234
  const cssModuleSetup = moduleBindings.map((m) => `_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(m.name)}] = ${m.bindingName};`).join("\n");
243
235
  output = output.replace(/^export default _sfc_main;/m, `${cssModuleSetup}\nexport default _sfc_main;`);
244
236
  }
245
- } else if (compiled.css && !(isProduction && extractCss)) {
246
- const cssCode = JSON.stringify(compiled.css);
247
- const cssId = JSON.stringify(`vize-style-${compiled.scopeId}`);
248
- output = `
249
- export const __vize_css__ = ${cssCode};
250
- const __vize_css_id__ = ${cssId};
237
+ } else if (compiled.css && !(isProduction && extractCss)) output = `
238
+ export const __vize_css__ = ${JSON.stringify(compiled.css)};
239
+ const __vize_css_id__ = ${JSON.stringify(`vize-style-${compiled.scopeId}`)};
251
240
  (function() {
252
241
  if (typeof document !== 'undefined') {
253
242
  let style = document.getElementById(__vize_css_id__);
@@ -262,23 +251,17 @@ const __vize_css_id__ = ${cssId};
262
251
  }
263
252
  })();
264
253
  ${output}`;
265
- }
266
254
  if (!isProduction && isDev && hasExportDefault) {
267
255
  const effectiveHmrUpdateType = hmrUpdateType === "template-only" && !supportsTemplateOnlyHmr(output) ? "full-reload" : hmrUpdateType ?? "full-reload";
268
256
  output += generateHmrCode(compiled.scopeId, effectiveHmrUpdateType);
269
257
  }
270
258
  return output;
271
259
  }
272
-
273
- //#endregion
274
- //#region src/virtual.ts
275
- const LEGACY_VIZE_PREFIX = "\0vize:";
276
260
  const VIZE_SSR_PREFIX = "\0vize-ssr:";
277
- const VIRTUAL_CSS_MODULE = "virtual:vize-styles";
278
261
  const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
279
262
  /** Check if a module ID is a vize-compiled virtual module */
280
263
  function isVizeVirtual(id) {
281
- const pathPart = id.startsWith(VIZE_SSR_PREFIX) ? id.slice(VIZE_SSR_PREFIX.length) : id.slice(1);
264
+ const pathPart = id.startsWith("\0vize-ssr:") ? id.slice(10) : id.slice(1);
282
265
  return id.startsWith("\0") && pathPart.endsWith(".vue.ts");
283
266
  }
284
267
  function isVizeSsrVirtual(id) {
@@ -290,7 +273,7 @@ function toVirtualId(realPath, ssr = false) {
290
273
  }
291
274
  /** Extract the real .vue file path from a virtual module ID */
292
275
  function fromVirtualId(virtualId) {
293
- const prefix = isVizeSsrVirtual(virtualId) ? VIZE_SSR_PREFIX.length : 1;
276
+ const prefix = isVizeSsrVirtual(virtualId) ? 10 : 1;
294
277
  return virtualId.slice(prefix, -3);
295
278
  }
296
279
  function escapeRegExp(value) {
@@ -317,10 +300,15 @@ function rewriteDynamicTemplateImports(code, aliasRules) {
317
300
  rewritten = rewritten.replace(/\bimport\s*\(\s*`/g, "import(/* @vite-ignore */ `");
318
301
  return rewritten;
319
302
  }
320
-
321
303
  //#endregion
322
304
  //#region src/transform.ts
323
305
  /**
306
+ * Code transformation utilities for Vize.
307
+ *
308
+ * Handles static asset URL rewriting, Vite define replacements, and
309
+ * provides the debug logger.
310
+ */
311
+ /**
324
312
  * Rewrite static asset URLs in compiled template output.
325
313
  *
326
314
  * Transforms property values like `src: "@/assets/logo.svg"` into import
@@ -391,9 +379,14 @@ function createLogger(debug) {
391
379
  error: (...args) => console.error("[vize]", ...args)
392
380
  };
393
381
  }
394
-
395
382
  //#endregion
396
383
  //#region src/config.ts
384
+ /**
385
+ * Vize configuration loading and management.
386
+ *
387
+ * Handles discovery, loading, and caching of vize.config.ts/js/json files,
388
+ * and provides the shared config store for inter-plugin communication.
389
+ */
397
390
  const CONFIG_FILES = [
398
391
  "vize.config.ts",
399
392
  "vize.config.js",
@@ -417,15 +410,12 @@ function defineConfig(config) {
417
410
  async function loadConfig(root, options = {}) {
418
411
  const { mode = "root", configFile, env } = options;
419
412
  if (mode === "none") return null;
420
- if (configFile) {
421
- const configPath = path.isAbsolute(configFile) ? configFile : path.resolve(root, configFile);
422
- return loadConfigFile(configPath, env);
423
- }
413
+ if (configFile) return loadConfigFile(path.isAbsolute(configFile) ? configFile : path.resolve(root, configFile), env);
424
414
  if (mode === "auto") {
425
415
  let searchDir = root;
426
416
  while (true) {
427
- const found$1 = findConfigInDir(searchDir);
428
- if (found$1) return loadConfigFile(found$1, env);
417
+ const found = findConfigInDir(searchDir);
418
+ if (found) return loadConfigFile(found, env);
429
419
  const parentDir = path.dirname(searchDir);
430
420
  if (parentDir === searchDir) break;
431
421
  searchDir = parentDir;
@@ -448,15 +438,13 @@ async function resolveConfigExport(exported, env) {
448
438
  }
449
439
  async function loadConfigFile(configPath, env) {
450
440
  if (!fs.existsSync(configPath)) return null;
451
- const ext = path.extname(configPath);
452
- if (ext === ".json") {
441
+ if (path.extname(configPath) === ".json") {
453
442
  const content = fs.readFileSync(configPath, "utf-8");
454
443
  return JSON.parse(content);
455
444
  }
456
445
  try {
457
446
  const module = await import(configPath);
458
- const exported = module.default ?? module;
459
- return resolveConfigExport(exported, env);
447
+ return resolveConfigExport(module.default ?? module, env);
460
448
  } catch (e) {
461
449
  console.warn(`[vize] Failed to load config from ${configPath}:`, e);
462
450
  return null;
@@ -467,8 +455,7 @@ async function loadConfigFile(configPath, env) {
467
455
  * Key = project root, Value = resolved VizeConfig.
468
456
  * Used by musea() and other plugins to access the unified config.
469
457
  */
470
- const vizeConfigStore = new Map();
471
-
458
+ const vizeConfigStore = /* @__PURE__ */ new Map();
472
459
  //#endregion
473
460
  //#region src/compile-options.ts
474
461
  function buildCompileFileOptions(filePath, source, options) {
@@ -487,7 +474,6 @@ function buildCompileBatchOptions(options) {
487
474
  vapor: options.vapor
488
475
  };
489
476
  }
490
-
491
477
  //#endregion
492
478
  //#region src/compiler.ts
493
479
  const { compileSfc, compileSfcBatchWithResults } = native;
@@ -549,12 +535,11 @@ function compileFile(filePath, cache, options, source) {
549
535
  * Returns per-file results with content hashes for HMR.
550
536
  */
551
537
  function compileBatch(files, cache, options) {
552
- const inputs = files.map((f) => ({
538
+ const result = compileSfcBatchWithResults(files.map((f) => ({
553
539
  path: f.path,
554
540
  source: f.source
555
- }));
556
- const result = compileSfcBatchWithResults(inputs, buildCompileBatchOptions(options));
557
- const sourceMap = new Map();
541
+ })), buildCompileBatchOptions(options));
542
+ const sourceMap = /* @__PURE__ */ new Map();
558
543
  for (const f of files) sourceMap.set(f.path, f.source);
559
544
  for (const fileResult of result.results) {
560
545
  if (fileResult.errors.length === 0) {
@@ -578,7 +563,6 @@ function compileBatch(files, cache, options) {
578
563
  }
579
564
  return result;
580
565
  }
581
-
582
566
  //#endregion
583
567
  //#region src/plugin/state.ts
584
568
  function hasFileMetadataChanged(previous, next) {
@@ -618,7 +602,7 @@ async function compileAll(state) {
618
602
  ignore: state.ignorePatterns,
619
603
  absolute: true
620
604
  });
621
- const currentMetadata = new Map();
605
+ const currentMetadata = /* @__PURE__ */ new Map();
622
606
  for (const file of files) try {
623
607
  const stat = fs.statSync(file);
624
608
  currentMetadata.set(file, {
@@ -639,8 +623,8 @@ async function compileAll(state) {
639
623
  }
640
624
  state.logger.info(`Pre-compiling ${files.length} Vue files... (${changedFiles.length} changed, ${cachedFileCount} cached, ${deletedFiles.length} removed)`);
641
625
  if (changedFiles.length === 0) {
642
- const elapsed$1 = (performance.now() - startTime).toFixed(2);
643
- state.logger.info(`Pre-compilation complete: cache reused (${elapsed$1}ms)`);
626
+ const elapsed = (performance.now() - startTime).toFixed(2);
627
+ state.logger.info(`Pre-compilation complete: cache reused (${elapsed}ms)`);
644
628
  return;
645
629
  }
646
630
  const fileContents = [];
@@ -678,7 +662,6 @@ async function compileAll(state) {
678
662
  const elapsed = (performance.now() - startTime).toFixed(2);
679
663
  state.logger.info(`Pre-compilation complete: ${result.successCount} recompiled, ${cachedFileCount} reused, ${result.failedCount} failed (${elapsed}ms, native batch: ${result.timeMs.toFixed(2)}ms)`);
680
664
  }
681
-
682
665
  //#endregion
683
666
  //#region src/plugin/resolve.ts
684
667
  function resolveVuePath(state, id, importer) {
@@ -704,14 +687,12 @@ function resolveBareImportWithNode(state, id, importer) {
704
687
  const [request, queryPart] = id.split("?");
705
688
  const querySuffix = queryPart ? `?${queryPart}` : "";
706
689
  const candidates = [normalizeRequireBase(importer), path.join(state.root, "package.json")].filter((candidate) => candidate != null);
707
- const seen = new Set();
690
+ const seen = /* @__PURE__ */ new Set();
708
691
  for (const candidate of candidates) {
709
692
  if (seen.has(candidate)) continue;
710
693
  seen.add(candidate);
711
694
  try {
712
- const requireFromBase = createRequire(candidate);
713
- const resolved = requireFromBase.resolve(request);
714
- return `${resolved}${querySuffix}`;
695
+ return `${createRequire(candidate).resolve(request)}${querySuffix}`;
715
696
  } catch {}
716
697
  }
717
698
  return null;
@@ -724,12 +705,12 @@ async function resolveIdHook(ctx, state, id, importer, options) {
724
705
  if (isSsrRequest && !isVizeSsrVirtual(id)) return toVirtualId(fromVirtualId(id), true);
725
706
  return null;
726
707
  }
727
- if (id.startsWith(LEGACY_VIZE_PREFIX)) {
728
- const rawPath = id.slice(LEGACY_VIZE_PREFIX.length);
729
- const cleanPath$1 = rawPath.endsWith(".ts") ? rawPath.slice(0, -3) : rawPath;
730
- if (!cleanPath$1.endsWith(".vue")) {
731
- state.logger.log(`resolveId: redirecting legacy virtual ID to ${cleanPath$1}`);
732
- return cleanPath$1;
708
+ if (id.startsWith("\0vize:")) {
709
+ const rawPath = id.slice(6);
710
+ const cleanPath = rawPath.endsWith(".ts") ? rawPath.slice(0, -3) : rawPath;
711
+ if (!cleanPath.endsWith(".vue")) {
712
+ state.logger.log(`resolveId: redirecting legacy virtual ID to ${cleanPath}`);
713
+ return cleanPath;
733
714
  }
734
715
  }
735
716
  const cleanPath = id.slice(1);
@@ -753,7 +734,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
753
734
  };
754
735
  return resolved;
755
736
  }
756
- if (id === VIRTUAL_CSS_MODULE) return RESOLVED_CSS_MODULE;
737
+ if (id === "virtual:vize-styles") return RESOLVED_CSS_MODULE;
757
738
  if (isBuild && id.startsWith("/@fs/")) return normalizeFsIdForBuild(id);
758
739
  if (id.includes("?macro=true")) {
759
740
  const filePath = id.split("?")[0];
@@ -777,8 +758,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
777
758
  }
778
759
  if (!id.endsWith(".vue")) {
779
760
  if (!id.startsWith("./") && !id.startsWith("../") && !id.startsWith("/")) {
780
- const matchesAlias = state.cssAliasRules.some((rule) => id === rule.find || id.startsWith(rule.find + "/"));
781
- if (!matchesAlias) {
761
+ if (!state.cssAliasRules.some((rule) => id === rule.find || id.startsWith(rule.find + "/"))) {
782
762
  try {
783
763
  const resolved = await ctx.resolve(id, cleanImporter, { skipSelf: true });
784
764
  if (resolved) {
@@ -869,8 +849,7 @@ async function resolveIdHook(ctx, state, id, importer, options) {
869
849
  const viteResolved = await ctx.resolve(id, importer, { skipSelf: true });
870
850
  if (viteResolved && viteResolved.id.endsWith(".vue")) {
871
851
  const realPath = viteResolved.id;
872
- const isResolvedNodeModules = realPath.includes("node_modules");
873
- if ((isResolvedNodeModules ? handleNodeModules : state.filter(realPath)) && (state.cache.has(realPath) || fs.existsSync(realPath))) {
852
+ if ((realPath.includes("node_modules") ? handleNodeModules : state.filter(realPath)) && (state.cache.has(realPath) || fs.existsSync(realPath))) {
874
853
  state.logger.log(`resolveId: resolved via Vite fallback ${id} to ${realPath}`);
875
854
  return toVirtualId(realPath, isSsrRequest);
876
855
  }
@@ -879,7 +858,6 @@ async function resolveIdHook(ctx, state, id, importer, options) {
879
858
  }
880
859
  return null;
881
860
  }
882
-
883
861
  //#endregion
884
862
  //#region src/plugin/load.ts
885
863
  const SERVER_PLACEHOLDER_CODE = `import { createElementBlock, defineComponent } from "vue";
@@ -902,10 +880,7 @@ function getOxcDumpPath(root, realPath) {
902
880
  }
903
881
  function loadHook(state, id, loadOptions) {
904
882
  const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
905
- if (id === RESOLVED_CSS_MODULE) {
906
- const allCss = Array.from(state.collectedCss.values()).join("\n\n");
907
- return allCss;
908
- }
883
+ if (id === "\0vize:all-styles.css") return Array.from(state.collectedCss.values()).join("\n\n");
909
884
  let styleId = id;
910
885
  if (id.startsWith("\0") && id.includes("?vue")) styleId = id.slice(1).replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
911
886
  if (styleId.includes("?vue&type=style") || styleId.includes("?vue=&type=style")) {
@@ -914,10 +889,9 @@ function loadHook(state, id, loadOptions) {
914
889
  const params = new URLSearchParams(queryString);
915
890
  const indexStr = params.get("index");
916
891
  const lang = params.get("lang");
917
- const _hasModule = params.has("module");
892
+ params.has("module");
918
893
  const scoped = params.get("scoped");
919
- const compiled = state.cache.get(realPath);
920
- const fallbackCompiled = compiled ?? state.ssrCache.get(realPath);
894
+ const fallbackCompiled = state.cache.get(realPath) ?? state.ssrCache.get(realPath);
921
895
  const blockIndex = indexStr !== null ? parseInt(indexStr, 10) : -1;
922
896
  if (fallbackCompiled?.styles && blockIndex >= 0 && blockIndex < fallbackCompiled.styles.length) {
923
897
  const block = fallbackCompiled.styles[blockIndex];
@@ -932,8 +906,7 @@ function loadHook(state, id, loadOptions) {
932
906
  else body.push(line);
933
907
  }
934
908
  const bodyContent = body.join("\n");
935
- const hoistedContent = hoisted.length > 0 ? hoisted.join("\n") + "\n\n" : "";
936
- styleContent = `${hoistedContent}[${scoped}] {\n${bodyContent}\n}`;
909
+ styleContent = `${hoisted.length > 0 ? hoisted.join("\n") + "\n\n" : ""}[${scoped}] {\n${bodyContent}\n}`;
937
910
  }
938
911
  return {
939
912
  code: styleContent,
@@ -946,15 +919,11 @@ function loadHook(state, id, loadOptions) {
946
919
  if (id.startsWith("\0") && id.endsWith("?macro=true")) {
947
920
  const realPath = id.slice(1).replace("?macro=true", "");
948
921
  if (fs.existsSync(realPath)) {
949
- const source = fs.readFileSync(realPath, "utf-8");
950
- const setupMatch = source.match(/<script\s+setup[^>]*>([\s\S]*?)<\/script>/);
951
- if (setupMatch) {
952
- const scriptContent = setupMatch[1];
953
- return {
954
- code: `${scriptContent}\nexport default {}`,
955
- map: null
956
- };
957
- }
922
+ const setupMatch = fs.readFileSync(realPath, "utf-8").match(/<script\s+setup[^>]*>([\s\S]*?)<\/script>/);
923
+ if (setupMatch) return {
924
+ code: `${setupMatch[1]}\nexport default {}`,
925
+ map: null
926
+ };
958
927
  }
959
928
  return {
960
929
  code: "export default {}",
@@ -1004,7 +973,7 @@ function loadHook(state, id, loadOptions) {
1004
973
  }
1005
974
  }
1006
975
  if (id.startsWith("\0")) {
1007
- const afterPrefix = id.startsWith(LEGACY_VIZE_PREFIX) ? id.slice(LEGACY_VIZE_PREFIX.length) : id.slice(1);
976
+ const afterPrefix = id.startsWith("\0vize:") ? id.slice(6) : id.slice(1);
1008
977
  if (afterPrefix.includes("?commonjs-")) return null;
1009
978
  const [pathPart, queryPart] = afterPrefix.split("?");
1010
979
  const querySuffix = queryPart ? `?${queryPart}` : "";
@@ -1043,7 +1012,6 @@ async function transformHook(state, code, id, options) {
1043
1012
  }
1044
1013
  return null;
1045
1014
  }
1046
-
1047
1015
  //#endregion
1048
1016
  //#region src/plugin/hmr.ts
1049
1017
  async function handleHotUpdateHook(state, ctx) {
@@ -1074,7 +1042,7 @@ async function handleHotUpdateHook(state, ctx) {
1074
1042
  const modules = server.moduleGraph.getModulesByFile(virtualId) ?? server.moduleGraph.getModulesByFile(file);
1075
1043
  const hasDelegated = hasDelegatedStyles(newCompiled);
1076
1044
  if (hasDelegated && updateType === "style-only") {
1077
- const affectedModules = new Set();
1045
+ const affectedModules = /* @__PURE__ */ new Set();
1078
1046
  for (const block of newCompiled.styles ?? []) {
1079
1047
  const params = new URLSearchParams();
1080
1048
  params.set("vue", "");
@@ -1125,15 +1093,13 @@ function handleGenerateBundleHook(state, emitFile) {
1125
1093
  state.logger.log(`Extracted CSS to assets/vize-components.css (${state.collectedCss.size} components)`);
1126
1094
  }
1127
1095
  }
1128
-
1129
1096
  //#endregion
1130
1097
  //#region src/plugin/compat.ts
1131
1098
  function createVueCompatPlugin(state) {
1132
1099
  let compilerSfc = null;
1133
1100
  const loadCompilerSfc = () => {
1134
1101
  if (!compilerSfc) try {
1135
- const require = createRequire(import.meta.url);
1136
- compilerSfc = require("@vue/compiler-sfc");
1102
+ compilerSfc = createRequire(import.meta.url)("@vue/compiler-sfc");
1137
1103
  } catch {
1138
1104
  compilerSfc = { parse: () => ({
1139
1105
  descriptor: {},
@@ -1163,14 +1129,12 @@ function createPostTransformPlugin(state) {
1163
1129
  state.logger.log(`post-transform: compiling virtual SFC content from ${id}`);
1164
1130
  try {
1165
1131
  const isSsr = !!transformOptions?.ssr;
1166
- const compiled = compileFile(id, getEnvironmentCache(state, isSsr), getCompileOptionsForRequest(state, isSsr), code);
1167
- const output = generateOutput(compiled, {
1132
+ const result = await transformWithOxc(generateOutput(compileFile(id, getEnvironmentCache(state, isSsr), getCompileOptionsForRequest(state, isSsr), code), {
1168
1133
  isProduction: state.isProduction,
1169
1134
  isDev: state.server !== null,
1170
1135
  extractCss: state.extractCss,
1171
1136
  filePath: id
1172
- });
1173
- const result = await transformWithOxc(output, id, { lang: "ts" });
1137
+ }), id, { lang: "ts" });
1174
1138
  const defines = transformOptions?.ssr ? state.serverViteDefine : state.clientViteDefine;
1175
1139
  let transformed = result.code;
1176
1140
  if (Object.keys(defines).length > 0) transformed = applyDefineReplacements(transformed, defines);
@@ -1186,16 +1150,15 @@ function createPostTransformPlugin(state) {
1186
1150
  }
1187
1151
  };
1188
1152
  }
1189
-
1190
1153
  //#endregion
1191
1154
  //#region src/plugin/index.ts
1192
1155
  function vize(options = {}) {
1193
1156
  const state = {
1194
- cache: new Map(),
1195
- ssrCache: new Map(),
1196
- collectedCss: new Map(),
1197
- precompileMetadata: new Map(),
1198
- pendingHmrUpdateTypes: new Map(),
1157
+ cache: /* @__PURE__ */ new Map(),
1158
+ ssrCache: /* @__PURE__ */ new Map(),
1159
+ collectedCss: /* @__PURE__ */ new Map(),
1160
+ precompileMetadata: /* @__PURE__ */ new Map(),
1161
+ pendingHmrUpdateTypes: /* @__PURE__ */ new Map(),
1199
1162
  isProduction: false,
1200
1163
  root: "",
1201
1164
  clientViteBase: "/",
@@ -1213,160 +1176,157 @@ function vize(options = {}) {
1213
1176
  serverViteDefine: {},
1214
1177
  logger: createLogger(options.debug ?? false)
1215
1178
  };
1216
- const mainPlugin = {
1217
- name: "vite-plugin-vize",
1218
- enforce: "pre",
1219
- config(userConfig, env) {
1220
- const cssModules = userConfig.css?.modules;
1221
- if (cssModules && typeof cssModules.generateScopedName === "function") {
1222
- const origFn = cssModules.generateScopedName;
1223
- cssModules.generateScopedName = function(name, filename, css) {
1224
- let clean = filename;
1225
- const nulIdx = clean.indexOf("\0");
1226
- if (nulIdx >= 0) clean = clean.slice(nulIdx + 1);
1227
- clean = clean.replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
1228
- if (clean.includes("?")) clean = clean.split("?")[0];
1229
- return origFn.call(this, name, clean, css);
1179
+ return [
1180
+ createVueCompatPlugin(state),
1181
+ {
1182
+ name: "vite-plugin-vize",
1183
+ enforce: "pre",
1184
+ config(userConfig, env) {
1185
+ const cssModules = userConfig.css?.modules;
1186
+ if (cssModules && typeof cssModules.generateScopedName === "function") {
1187
+ const origFn = cssModules.generateScopedName;
1188
+ cssModules.generateScopedName = function(name, filename, css) {
1189
+ let clean = filename;
1190
+ const nulIdx = clean.indexOf("\0");
1191
+ if (nulIdx >= 0) clean = clean.slice(nulIdx + 1);
1192
+ clean = clean.replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
1193
+ if (clean.includes("?")) clean = clean.split("?")[0];
1194
+ return origFn.call(this, name, clean, css);
1195
+ };
1196
+ }
1197
+ return {
1198
+ define: {
1199
+ __VUE_OPTIONS_API__: true,
1200
+ __VUE_PROD_DEVTOOLS__: env.command === "serve",
1201
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
1202
+ },
1203
+ optimizeDeps: { exclude: ["virtual:vize-styles"] }
1230
1204
  };
1231
- }
1232
- return {
1233
- define: {
1234
- __VUE_OPTIONS_API__: true,
1235
- __VUE_PROD_DEVTOOLS__: env.command === "serve",
1236
- __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
1237
- },
1238
- optimizeDeps: { exclude: ["virtual:vize-styles"] }
1239
- };
1240
- },
1241
- async configResolved(resolvedConfig) {
1242
- state.root = options.root ?? resolvedConfig.root;
1243
- state.isProduction = options.isProduction ?? resolvedConfig.isProduction;
1244
- const isSsrBuild = !!resolvedConfig.build?.ssr;
1245
- const currentBase = resolvedConfig.command === "serve" ? options.devUrlBase ?? resolvedConfig.base ?? "/" : resolvedConfig.base ?? "/";
1246
- if (isSsrBuild) state.serverViteBase = currentBase;
1247
- else state.clientViteBase = currentBase;
1248
- state.extractCss = state.isProduction;
1249
- const isSsr = !!resolvedConfig.build?.ssr;
1250
- const envDefine = {};
1251
- if (resolvedConfig.define) for (const [key, value] of Object.entries(resolvedConfig.define)) {
1252
- if (isBuiltinDefine(key)) continue;
1253
- if (typeof value === "string") envDefine[key] = value;
1254
- else envDefine[key] = JSON.stringify(value);
1255
- }
1256
- if (isSsr) state.serverViteDefine = envDefine;
1257
- else state.clientViteDefine = envDefine;
1258
- const configEnv = {
1259
- mode: resolvedConfig.mode,
1260
- command: resolvedConfig.command === "build" ? "build" : "serve",
1261
- isSsrBuild: !!resolvedConfig.build?.ssr
1262
- };
1263
- let fileConfig = null;
1264
- if (options.configMode !== false) {
1265
- fileConfig = await loadConfig(state.root, {
1266
- mode: options.configMode ?? "root",
1267
- configFile: options.configFile,
1268
- env: configEnv
1269
- });
1270
- if (fileConfig) {
1271
- state.logger.log("Loaded config from vize.config file");
1272
- vizeConfigStore.set(state.root, fileConfig);
1205
+ },
1206
+ async configResolved(resolvedConfig) {
1207
+ state.root = options.root ?? resolvedConfig.root;
1208
+ state.isProduction = options.isProduction ?? resolvedConfig.isProduction;
1209
+ const isSsrBuild = !!resolvedConfig.build?.ssr;
1210
+ const currentBase = resolvedConfig.command === "serve" ? options.devUrlBase ?? resolvedConfig.base ?? "/" : resolvedConfig.base ?? "/";
1211
+ if (isSsrBuild) state.serverViteBase = currentBase;
1212
+ else state.clientViteBase = currentBase;
1213
+ state.extractCss = state.isProduction;
1214
+ const isSsr = !!resolvedConfig.build?.ssr;
1215
+ const envDefine = {};
1216
+ if (resolvedConfig.define) for (const [key, value] of Object.entries(resolvedConfig.define)) {
1217
+ if (isBuiltinDefine(key)) continue;
1218
+ if (typeof value === "string") envDefine[key] = value;
1219
+ else envDefine[key] = JSON.stringify(value);
1273
1220
  }
1274
- }
1275
- const viteConfig = fileConfig?.vite ?? {};
1276
- const compilerConfig = fileConfig?.compiler ?? {};
1277
- state.mergedOptions = {
1278
- ...options,
1279
- ssr: options.ssr ?? compilerConfig.ssr ?? false,
1280
- sourceMap: options.sourceMap ?? compilerConfig.sourceMap,
1281
- vapor: options.vapor ?? compilerConfig.vapor ?? false,
1282
- include: options.include ?? viteConfig.include,
1283
- exclude: options.exclude ?? viteConfig.exclude,
1284
- scanPatterns: options.scanPatterns ?? viteConfig.scanPatterns,
1285
- ignorePatterns: options.ignorePatterns ?? viteConfig.ignorePatterns
1286
- };
1287
- state.dynamicImportAliasRules = [];
1288
- for (const alias of resolvedConfig.resolve.alias) {
1289
- if (typeof alias.find !== "string" || typeof alias.replacement !== "string") continue;
1290
- const fromPrefix = alias.find.endsWith("/") ? alias.find : `${alias.find}/`;
1291
- const replacement = toBrowserImportPrefix(alias.replacement);
1292
- const toPrefix = replacement.endsWith("/") ? replacement : `${replacement}/`;
1293
- state.dynamicImportAliasRules.push({
1294
- fromPrefix,
1295
- toPrefix
1296
- });
1297
- }
1298
- state.dynamicImportAliasRules.sort((a, b) => b.fromPrefix.length - a.fromPrefix.length);
1299
- state.cssAliasRules = [];
1300
- for (const alias of resolvedConfig.resolve.alias) {
1301
- if (typeof alias.find !== "string" || typeof alias.replacement !== "string") continue;
1302
- state.cssAliasRules.push({
1303
- find: alias.find,
1304
- replacement: alias.replacement
1305
- });
1306
- }
1307
- state.cssAliasRules.sort((a, b) => b.find.length - a.find.length);
1308
- state.filter = createFilter(state.mergedOptions.include, state.mergedOptions.exclude);
1309
- state.scanPatterns = state.mergedOptions.scanPatterns ?? ["**/*.vue"];
1310
- state.ignorePatterns = state.mergedOptions.ignorePatterns ?? [
1311
- "node_modules/**",
1312
- "dist/**",
1313
- ".git/**"
1314
- ];
1315
- state.initialized = true;
1316
- },
1317
- configureServer(devServer) {
1318
- state.server = devServer;
1319
- devServer.middlewares.use((req, _res, next) => {
1320
- if (req.url && req.url.includes("__x00__")) {
1321
- const [urlPath, queryPart] = req.url.split("?");
1322
- let cleanedPath = urlPath.replace(/__x00__/g, "");
1323
- cleanedPath = cleanedPath.replace(/^\/@id\/\//, "/@fs/");
1324
- if (cleanedPath.startsWith("/@fs/")) {
1325
- const fsPath = cleanedPath.slice(4);
1326
- if (fsPath.startsWith("/") && fs.existsSync(fsPath) && fs.statSync(fsPath).isFile() && !fsPath.endsWith(".vue.ts")) {
1327
- const cleaned = queryPart ? `${cleanedPath}?${queryPart}` : cleanedPath;
1328
- if (cleaned !== req.url) {
1329
- state.logger.log(`middleware: rewriting ${req.url} -> ${cleaned}`);
1330
- req.url = cleaned;
1221
+ if (isSsr) state.serverViteDefine = envDefine;
1222
+ else state.clientViteDefine = envDefine;
1223
+ const configEnv = {
1224
+ mode: resolvedConfig.mode,
1225
+ command: resolvedConfig.command === "build" ? "build" : "serve",
1226
+ isSsrBuild: !!resolvedConfig.build?.ssr
1227
+ };
1228
+ let fileConfig = null;
1229
+ if (options.configMode !== false) {
1230
+ fileConfig = await loadConfig(state.root, {
1231
+ mode: options.configMode ?? "root",
1232
+ configFile: options.configFile,
1233
+ env: configEnv
1234
+ });
1235
+ if (fileConfig) {
1236
+ state.logger.log("Loaded config from vize.config file");
1237
+ vizeConfigStore.set(state.root, fileConfig);
1238
+ }
1239
+ }
1240
+ const viteConfig = fileConfig?.vite ?? {};
1241
+ const compilerConfig = fileConfig?.compiler ?? {};
1242
+ state.mergedOptions = {
1243
+ ...options,
1244
+ ssr: options.ssr ?? compilerConfig.ssr ?? false,
1245
+ sourceMap: options.sourceMap ?? compilerConfig.sourceMap,
1246
+ vapor: options.vapor ?? compilerConfig.vapor ?? false,
1247
+ include: options.include ?? viteConfig.include,
1248
+ exclude: options.exclude ?? viteConfig.exclude,
1249
+ scanPatterns: options.scanPatterns ?? viteConfig.scanPatterns,
1250
+ ignorePatterns: options.ignorePatterns ?? viteConfig.ignorePatterns
1251
+ };
1252
+ state.dynamicImportAliasRules = [];
1253
+ for (const alias of resolvedConfig.resolve.alias) {
1254
+ if (typeof alias.find !== "string" || typeof alias.replacement !== "string") continue;
1255
+ const fromPrefix = alias.find.endsWith("/") ? alias.find : `${alias.find}/`;
1256
+ const replacement = toBrowserImportPrefix(alias.replacement);
1257
+ const toPrefix = replacement.endsWith("/") ? replacement : `${replacement}/`;
1258
+ state.dynamicImportAliasRules.push({
1259
+ fromPrefix,
1260
+ toPrefix
1261
+ });
1262
+ }
1263
+ state.dynamicImportAliasRules.sort((a, b) => b.fromPrefix.length - a.fromPrefix.length);
1264
+ state.cssAliasRules = [];
1265
+ for (const alias of resolvedConfig.resolve.alias) {
1266
+ if (typeof alias.find !== "string" || typeof alias.replacement !== "string") continue;
1267
+ state.cssAliasRules.push({
1268
+ find: alias.find,
1269
+ replacement: alias.replacement
1270
+ });
1271
+ }
1272
+ state.cssAliasRules.sort((a, b) => b.find.length - a.find.length);
1273
+ state.filter = createFilter(state.mergedOptions.include, state.mergedOptions.exclude);
1274
+ state.scanPatterns = state.mergedOptions.scanPatterns ?? ["**/*.vue"];
1275
+ state.ignorePatterns = state.mergedOptions.ignorePatterns ?? [
1276
+ "node_modules/**",
1277
+ "dist/**",
1278
+ ".git/**"
1279
+ ];
1280
+ state.initialized = true;
1281
+ },
1282
+ configureServer(devServer) {
1283
+ state.server = devServer;
1284
+ devServer.middlewares.use((req, _res, next) => {
1285
+ if (req.url && req.url.includes("__x00__")) {
1286
+ const [urlPath, queryPart] = req.url.split("?");
1287
+ let cleanedPath = urlPath.replace(/__x00__/g, "");
1288
+ cleanedPath = cleanedPath.replace(/^\/@id\/\//, "/@fs/");
1289
+ if (cleanedPath.startsWith("/@fs/")) {
1290
+ const fsPath = cleanedPath.slice(4);
1291
+ if (fsPath.startsWith("/") && fs.existsSync(fsPath) && fs.statSync(fsPath).isFile() && !fsPath.endsWith(".vue.ts")) {
1292
+ const cleaned = queryPart ? `${cleanedPath}?${queryPart}` : cleanedPath;
1293
+ if (cleaned !== req.url) {
1294
+ state.logger.log(`middleware: rewriting ${req.url} -> ${cleaned}`);
1295
+ req.url = cleaned;
1296
+ }
1331
1297
  }
1332
1298
  }
1333
1299
  }
1334
- }
1335
- next();
1336
- });
1337
- },
1338
- async buildStart() {
1339
- if (!state.scanPatterns) return;
1340
- await compileAll(state);
1341
- state.logger.log("Cache keys:", [...state.cache.keys()].slice(0, 3));
1342
- },
1343
- resolveId(id, importer, options$1) {
1344
- return resolveIdHook(this, state, id, importer, options$1);
1345
- },
1346
- load(id, loadOptions) {
1347
- return loadHook(state, id, loadOptions);
1348
- },
1349
- async transform(code, id, transformOptions) {
1350
- return transformHook(state, code, id, transformOptions);
1351
- },
1352
- async handleHotUpdate(ctx) {
1353
- return handleHotUpdateHook(state, ctx);
1300
+ next();
1301
+ });
1302
+ },
1303
+ async buildStart() {
1304
+ if (!state.scanPatterns) return;
1305
+ await compileAll(state);
1306
+ state.logger.log("Cache keys:", [...state.cache.keys()].slice(0, 3));
1307
+ },
1308
+ resolveId(id, importer, options) {
1309
+ return resolveIdHook(this, state, id, importer, options);
1310
+ },
1311
+ load(id, loadOptions) {
1312
+ return loadHook(state, id, loadOptions);
1313
+ },
1314
+ async transform(code, id, transformOptions) {
1315
+ return transformHook(state, code, id, transformOptions);
1316
+ },
1317
+ async handleHotUpdate(ctx) {
1318
+ return handleHotUpdateHook(state, ctx);
1319
+ },
1320
+ generateBundle() {
1321
+ handleGenerateBundleHook(state, this.emitFile.bind(this));
1322
+ }
1354
1323
  },
1355
- generateBundle() {
1356
- handleGenerateBundleHook(state, this.emitFile.bind(this));
1357
- }
1358
- };
1359
- return [
1360
- createVueCompatPlugin(state),
1361
- mainPlugin,
1362
1324
  createPostTransformPlugin(state)
1363
1325
  ];
1364
1326
  }
1365
-
1366
1327
  //#endregion
1367
1328
  //#region src/index.ts
1368
1329
  const __internal = { rewriteStaticAssetUrls };
1369
1330
  var src_default = vize;
1370
-
1371
1331
  //#endregion
1372
- export { __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };
1332
+ export { __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };
package/package.json CHANGED
@@ -1,58 +1,57 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "type": "module",
9
- "main": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
15
- }
16
- },
17
- "files": [
18
- "dist"
19
- ],
20
5
  "keywords": [
21
- "vite",
22
- "vue",
23
- "plugin",
24
- "sfc",
25
6
  "compiler",
7
+ "fast",
26
8
  "native",
27
- "fast"
9
+ "plugin",
10
+ "sfc",
11
+ "vite",
12
+ "vue"
28
13
  ],
14
+ "license": "MIT",
29
15
  "repository": {
30
16
  "type": "git",
31
17
  "url": "https://github.com/ubugeeei/vize",
32
18
  "directory": "npm/vite-plugin-vize"
33
19
  },
34
- "license": "MIT",
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "type": "module",
24
+ "main": "./dist/index.mjs",
25
+ "types": "./dist/index.d.mts",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.mjs",
29
+ "types": "./dist/index.d.mts"
30
+ }
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "tinyglobby": "^0.2.0",
37
+ "@vizejs/native": "0.34.0"
38
+ },
35
39
  "devDependencies": {
36
40
  "@types/node": "^22.0.0",
37
- "tsdown": "^0.9.0",
38
41
  "tsx": "^4.21.0",
39
42
  "typescript": "~5.6.0",
40
- "vite": "^8.0.0"
43
+ "vite": "npm:@voidzero-dev/vite-plus-core@latest",
44
+ "vite-plus": "latest"
41
45
  },
42
46
  "peerDependencies": {
43
47
  "vite": "^8.0.0"
44
48
  },
45
- "dependencies": {
46
- "tinyglobby": "^0.2.0",
47
- "@vizejs/native": "0.32.0"
48
- },
49
49
  "scripts": {
50
- "build": "tsdown",
51
- "dev": "tsdown --watch",
52
- "lint": "oxlint --deny-warnings --type-aware --tsconfig tsconfig.json",
53
- "lint:fix": "oxlint --type-aware --tsconfig tsconfig.json --fix",
54
- "fmt": "oxfmt --write src tsdown.config.ts",
55
- "fmt:check": "oxfmt src tsdown.config.ts",
50
+ "build": "vp pack",
51
+ "dev": "vp pack --watch",
52
+ "check": "vp check src vite.config.ts",
53
+ "check:fix": "vp check --fix src vite.config.ts",
54
+ "fmt": "vp fmt --write src vite.config.ts",
56
55
  "test": "node --import tsx src/test.ts"
57
56
  }
58
57
  }