@vizejs/vite-plugin 0.0.1-alpha.8 → 0.0.1-alpha.81

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.js CHANGED
@@ -1,141 +1,537 @@
1
- import path from 'node:path';
2
- import { glob } from 'tinyglobby';
3
- import { compileFile } from './compiler.js';
4
- import { createFilter, generateOutput } from './utils.js';
5
- const VIRTUAL_PREFIX = '\0vize:';
6
- export function vize(options = {}) {
7
- const filter = createFilter(options.include, options.exclude);
8
- const cache = new Map();
9
- // Map from virtual ID to real file path
10
- const virtualToReal = new Map();
11
- let isProduction;
12
- let root;
13
- let server = null;
14
- const scanPatterns = options.scanPatterns ?? ['**/*.vue'];
15
- const ignorePatterns = options.ignorePatterns ?? [
16
- 'node_modules/**',
17
- 'dist/**',
18
- '.git/**',
19
- ];
20
- async function compileAll() {
21
- const startTime = performance.now();
22
- const files = await glob(scanPatterns, {
23
- cwd: root,
24
- ignore: ignorePatterns,
25
- absolute: true,
26
- });
27
- console.log(`[vize] Pre-compiling ${files.length} Vue files...`);
28
- let successCount = 0;
29
- let errorCount = 0;
30
- for (const file of files) {
31
- try {
32
- compileFile(file, cache, {
33
- sourceMap: options.sourceMap ?? !isProduction,
34
- ssr: options.ssr ?? false,
35
- });
36
- successCount++;
37
- }
38
- catch (e) {
39
- errorCount++;
40
- console.error(`[vize] Failed to compile ${file}:`, e);
41
- }
42
- }
43
- const elapsed = (performance.now() - startTime).toFixed(2);
44
- console.log(`[vize] Pre-compilation complete: ${successCount} succeeded, ${errorCount} failed (${elapsed}ms)`);
1
+ import { transformWithOxc } from "vite";
2
+ import path from "node:path";
3
+ import fs from "node:fs";
4
+ import { glob } from "tinyglobby";
5
+ import * as native from "@vizejs/native";
6
+ import { createHash } from "node:crypto";
7
+
8
+ //#region src/hmr.ts
9
+ /**
10
+ * Detect the type of HMR update needed based on content hash changes.
11
+ *
12
+ * @param prev - Previously compiled module (undefined if first compile)
13
+ * @param next - Newly compiled module
14
+ * @returns The type of HMR update needed
15
+ */
16
+ function detectHmrUpdateType(prev, next) {
17
+ if (!prev) return "full-reload";
18
+ const scriptChanged = prev.scriptHash !== next.scriptHash;
19
+ if (scriptChanged) return "full-reload";
20
+ const templateChanged = prev.templateHash !== next.templateHash;
21
+ const styleChanged = prev.styleHash !== next.styleHash;
22
+ if (styleChanged && !templateChanged) return "style-only";
23
+ if (templateChanged) return "template-only";
24
+ return "full-reload";
25
+ }
26
+ /**
27
+ * Generate HMR-aware code output based on update type.
28
+ */
29
+ function generateHmrCode(scopeId, updateType) {
30
+ return `
31
+ if (import.meta.hot) {
32
+ _sfc_main.__hmrId = ${JSON.stringify(scopeId)};
33
+ _sfc_main.__hmrUpdateType = ${JSON.stringify(updateType)};
34
+
35
+ import.meta.hot.accept((mod) => {
36
+ if (!mod) return;
37
+ const { default: updated } = mod;
38
+ if (typeof __VUE_HMR_RUNTIME__ !== 'undefined') {
39
+ const updateType = updated.__hmrUpdateType || 'full-reload';
40
+ if (updateType === 'template-only') {
41
+ __VUE_HMR_RUNTIME__.rerender(updated.__hmrId, updated.render);
42
+ } else {
43
+ __VUE_HMR_RUNTIME__.reload(updated.__hmrId, updated);
44
+ }
45
45
  }
46
- function resolveVuePath(id, importer) {
47
- let resolved;
48
- if (path.isAbsolute(id)) {
49
- resolved = id;
50
- }
51
- else if (importer) {
52
- // Remove virtual prefix from importer if present
53
- const realImporter = importer.startsWith(VIRTUAL_PREFIX)
54
- ? virtualToReal.get(importer) ?? importer.slice(VIRTUAL_PREFIX.length)
55
- : importer;
56
- resolved = path.resolve(path.dirname(realImporter), id);
57
- }
58
- else {
59
- resolved = path.resolve(root, id);
60
- }
61
- return path.normalize(resolved);
46
+ });
47
+
48
+ import.meta.hot.on('vize:update', (data) => {
49
+ if (data.id !== _sfc_main.__hmrId) return;
50
+
51
+ if (data.type === 'style-only') {
52
+ // Update styles without remounting component
53
+ const styleId = 'vize-style-' + _sfc_main.__hmrId;
54
+ const styleEl = document.getElementById(styleId);
55
+ if (styleEl && data.css) {
56
+ styleEl.textContent = data.css;
57
+ }
62
58
  }
63
- return {
64
- name: 'vite-plugin-vize',
65
- enforce: 'pre',
66
- configResolved(resolvedConfig) {
67
- isProduction = options.isProduction ?? resolvedConfig.isProduction;
68
- root = options.root ?? resolvedConfig.root;
69
- },
70
- configureServer(devServer) {
71
- server = devServer;
72
- },
73
- async buildStart() {
74
- await compileAll();
75
- },
76
- resolveId(id, importer) {
77
- if (id.includes('?vue&type=style')) {
78
- return id;
79
- }
80
- if (id.endsWith('.vue')) {
81
- const resolved = resolveVuePath(id, importer);
82
- // Return virtual module ID if cached
83
- if (cache.has(resolved)) {
84
- const virtualId = VIRTUAL_PREFIX + resolved;
85
- virtualToReal.set(virtualId, resolved);
86
- return virtualId;
87
- }
88
- }
89
- return null;
90
- },
91
- load(id) {
92
- if (id.includes('?vue&type=style')) {
93
- const [filename] = id.split('?');
94
- const realPath = filename.startsWith(VIRTUAL_PREFIX)
95
- ? virtualToReal.get(filename) ?? filename.slice(VIRTUAL_PREFIX.length)
96
- : filename;
97
- const compiled = cache.get(realPath);
98
- if (compiled?.css) {
99
- return compiled.css;
100
- }
101
- return '';
102
- }
103
- // Handle virtual module
104
- if (id.startsWith(VIRTUAL_PREFIX)) {
105
- const realPath = virtualToReal.get(id) ?? id.slice(VIRTUAL_PREFIX.length);
106
- const compiled = cache.get(realPath);
107
- if (compiled) {
108
- return {
109
- code: generateOutput(compiled, isProduction, server !== null),
110
- map: null,
111
- };
112
- }
113
- }
114
- return null;
115
- },
116
- async handleHotUpdate(ctx) {
117
- const { file, server, read } = ctx;
118
- if (file.endsWith('.vue') && filter(file)) {
119
- try {
120
- const source = await read();
121
- compileFile(file, cache, {
122
- sourceMap: options.sourceMap ?? !isProduction,
123
- ssr: options.ssr ?? false,
124
- }, source);
125
- console.log(`[vize] Re-compiled: ${path.relative(root, file)}`);
126
- }
127
- catch (e) {
128
- console.error(`[vize] Re-compilation failed for ${file}:`, e);
129
- }
130
- // Find the virtual module for this file
131
- const virtualId = VIRTUAL_PREFIX + file;
132
- const modules = server.moduleGraph.getModulesByFile(virtualId)
133
- ?? server.moduleGraph.getModulesByFile(file);
134
- if (modules) {
135
- return [...modules];
136
- }
137
- }
138
- },
139
- };
59
+ });
60
+
61
+ if (typeof __VUE_HMR_RUNTIME__ !== 'undefined') {
62
+ __VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main);
63
+ }
64
+ }`;
65
+ }
66
+
67
+ //#endregion
68
+ //#region src/utils.ts
69
+ function generateScopeId(filename) {
70
+ const hash = createHash("sha256").update(filename).digest("hex");
71
+ return hash.slice(0, 8);
72
+ }
73
+ function createFilter(include, exclude) {
74
+ const includePatterns = include ? Array.isArray(include) ? include : [include] : [/\.vue$/];
75
+ const excludePatterns = exclude ? Array.isArray(exclude) ? exclude : [exclude] : [/node_modules/];
76
+ return (id) => {
77
+ const matchInclude = includePatterns.some((pattern) => typeof pattern === "string" ? id.includes(pattern) : pattern.test(id));
78
+ const matchExclude = excludePatterns.some((pattern) => typeof pattern === "string" ? id.includes(pattern) : pattern.test(id));
79
+ return matchInclude && !matchExclude;
80
+ };
81
+ }
82
+ function generateOutput(compiled, options) {
83
+ const { isProduction, isDev, hmrUpdateType, extractCss } = options;
84
+ let output = compiled.code;
85
+ const exportDefaultRegex = /^export default /m;
86
+ const hasExportDefault = exportDefaultRegex.test(output);
87
+ const hasSfcMainDefined = /\bconst\s+_sfc_main\s*=/.test(output);
88
+ if (hasExportDefault && !hasSfcMainDefined) {
89
+ output = output.replace(exportDefaultRegex, "const _sfc_main = ");
90
+ if (compiled.hasScoped && compiled.scopeId) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
91
+ output += "\nexport default _sfc_main;";
92
+ } else if (hasExportDefault && hasSfcMainDefined) {
93
+ if (compiled.hasScoped && compiled.scopeId) output = output.replace(/^export default _sfc_main/m, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";\nexport default _sfc_main`);
94
+ }
95
+ if (compiled.css && !(isProduction && extractCss)) {
96
+ const cssCode = JSON.stringify(compiled.css);
97
+ const cssId = JSON.stringify(`vize-style-${compiled.scopeId}`);
98
+ output = `
99
+ const __vize_css__ = ${cssCode};
100
+ const __vize_css_id__ = ${cssId};
101
+ (function() {
102
+ if (typeof document !== 'undefined') {
103
+ let style = document.getElementById(__vize_css_id__);
104
+ if (!style) {
105
+ style = document.createElement('style');
106
+ style.id = __vize_css_id__;
107
+ style.textContent = __vize_css__;
108
+ document.head.appendChild(style);
109
+ } else {
110
+ style.textContent = __vize_css__;
111
+ }
112
+ }
113
+ })();
114
+ ${output}`;
115
+ }
116
+ if (!isProduction && isDev && hasExportDefault) output += generateHmrCode(compiled.scopeId, hmrUpdateType ?? "full-reload");
117
+ return output;
118
+ }
119
+
120
+ //#endregion
121
+ //#region src/compiler.ts
122
+ const { compileSfc, compileSfcBatchWithResults } = native;
123
+ function compileFile(filePath, cache, options, source) {
124
+ const content = source ?? fs.readFileSync(filePath, "utf-8");
125
+ const scopeId = generateScopeId(filePath);
126
+ const hasScoped = /<style[^>]*\bscoped\b/.test(content);
127
+ const result = compileSfc(content, {
128
+ filename: filePath,
129
+ sourceMap: options.sourceMap,
130
+ ssr: options.ssr,
131
+ scopeId: hasScoped ? `data-v-${scopeId}` : void 0
132
+ });
133
+ if (result.errors.length > 0) {
134
+ const errorMsg = result.errors.join("\n");
135
+ console.error(`[vize] Compilation error in ${filePath}:\n${errorMsg}`);
136
+ }
137
+ if (result.warnings.length > 0) result.warnings.forEach((warning) => {
138
+ console.warn(`[vize] Warning in ${filePath}: ${warning}`);
139
+ });
140
+ const compiled = {
141
+ code: result.code,
142
+ css: result.css,
143
+ scopeId,
144
+ hasScoped
145
+ };
146
+ cache.set(filePath, compiled);
147
+ return compiled;
148
+ }
149
+ /**
150
+ * Batch compile multiple files in parallel using native Rust multithreading.
151
+ * Returns per-file results with content hashes for HMR.
152
+ */
153
+ function compileBatch(files, cache, options) {
154
+ const inputs = files.map((f) => ({
155
+ path: f.path,
156
+ source: f.source
157
+ }));
158
+ const result = compileSfcBatchWithResults(inputs, { ssr: options.ssr });
159
+ for (const fileResult of result.results) {
160
+ if (fileResult.errors.length === 0) cache.set(fileResult.path, {
161
+ code: fileResult.code,
162
+ css: fileResult.css,
163
+ scopeId: fileResult.scopeId,
164
+ hasScoped: fileResult.hasScoped,
165
+ templateHash: fileResult.templateHash,
166
+ styleHash: fileResult.styleHash,
167
+ scriptHash: fileResult.scriptHash
168
+ });
169
+ if (fileResult.errors.length > 0) console.error(`[vize] Compilation error in ${fileResult.path}:\n${fileResult.errors.join("\n")}`);
170
+ if (fileResult.warnings.length > 0) fileResult.warnings.forEach((warning) => {
171
+ console.warn(`[vize] Warning in ${fileResult.path}: ${warning}`);
172
+ });
173
+ }
174
+ return result;
175
+ }
176
+
177
+ //#endregion
178
+ //#region src/index.ts
179
+ const CONFIG_FILES = [
180
+ "vize.config.ts",
181
+ "vize.config.js",
182
+ "vize.config.mjs",
183
+ "vize.config.json"
184
+ ];
185
+ const DEFAULT_CONFIG_ENV = {
186
+ mode: "development",
187
+ command: "serve"
188
+ };
189
+ /**
190
+ * Define a Vize configuration with type checking.
191
+ * Accepts a plain object or a function that receives ConfigEnv.
192
+ */
193
+ function defineConfig(config) {
194
+ return config;
195
+ }
196
+ /**
197
+ * Load Vize configuration from file
198
+ */
199
+ async function loadConfig(root, options = {}) {
200
+ const { mode = "root", configFile, env } = options;
201
+ if (mode === "none") return null;
202
+ if (configFile) {
203
+ const configPath = path.isAbsolute(configFile) ? configFile : path.resolve(root, configFile);
204
+ return loadConfigFile(configPath, env);
205
+ }
206
+ if (mode === "auto") {
207
+ let searchDir = root;
208
+ while (true) {
209
+ const found$1 = findConfigInDir(searchDir);
210
+ if (found$1) return loadConfigFile(found$1, env);
211
+ const parentDir = path.dirname(searchDir);
212
+ if (parentDir === searchDir) break;
213
+ searchDir = parentDir;
214
+ }
215
+ return null;
216
+ }
217
+ const found = findConfigInDir(root);
218
+ return found ? loadConfigFile(found, env) : null;
219
+ }
220
+ function findConfigInDir(dir) {
221
+ for (const filename of CONFIG_FILES) {
222
+ const configPath = path.join(dir, filename);
223
+ if (fs.existsSync(configPath)) return configPath;
224
+ }
225
+ return null;
226
+ }
227
+ async function resolveConfigExport(exported, env) {
228
+ if (typeof exported === "function") return exported(env ?? DEFAULT_CONFIG_ENV);
229
+ return exported;
230
+ }
231
+ async function loadConfigFile(configPath, env) {
232
+ if (!fs.existsSync(configPath)) return null;
233
+ const ext = path.extname(configPath);
234
+ if (ext === ".json") {
235
+ const content = fs.readFileSync(configPath, "utf-8");
236
+ return JSON.parse(content);
237
+ }
238
+ try {
239
+ const module = await import(configPath);
240
+ const exported = module.default ?? module;
241
+ return resolveConfigExport(exported, env);
242
+ } catch (e) {
243
+ console.warn(`[vize] Failed to load config from ${configPath}:`, e);
244
+ return null;
245
+ }
246
+ }
247
+ /**
248
+ * Shared config store for inter-plugin communication.
249
+ * Key = project root, Value = resolved VizeConfig.
250
+ * Used by musea() and other plugins to access the unified config.
251
+ */
252
+ const vizeConfigStore = new Map();
253
+ const VIRTUAL_PREFIX = "\0vize:";
254
+ const VIRTUAL_CSS_MODULE = "virtual:vize-styles";
255
+ const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
256
+ function createLogger(debug) {
257
+ return {
258
+ log: (...args) => debug && console.log("[vize]", ...args),
259
+ info: (...args) => console.log("[vize]", ...args),
260
+ warn: (...args) => console.warn("[vize]", ...args),
261
+ error: (...args) => console.error("[vize]", ...args)
262
+ };
263
+ }
264
+ function vize(options = {}) {
265
+ const cache = new Map();
266
+ const virtualToReal = new Map();
267
+ const collectedCss = new Map();
268
+ let isProduction;
269
+ let root;
270
+ let server = null;
271
+ let filter;
272
+ let scanPatterns;
273
+ let ignorePatterns;
274
+ let mergedOptions;
275
+ let extractCss = false;
276
+ const logger = createLogger(options.debug ?? false);
277
+ async function compileAll() {
278
+ const startTime = performance.now();
279
+ const files = await glob(scanPatterns, {
280
+ cwd: root,
281
+ ignore: ignorePatterns,
282
+ absolute: true
283
+ });
284
+ logger.info(`Pre-compiling ${files.length} Vue files...`);
285
+ const fileContents = [];
286
+ for (const file of files) try {
287
+ const source = fs.readFileSync(file, "utf-8");
288
+ fileContents.push({
289
+ path: file,
290
+ source
291
+ });
292
+ } catch (e) {
293
+ logger.error(`Failed to read ${file}:`, e);
294
+ }
295
+ const result = compileBatch(fileContents, cache, { ssr: mergedOptions.ssr ?? false });
296
+ if (isProduction) {
297
+ for (const fileResult of result.results) if (fileResult.css) collectedCss.set(fileResult.path, fileResult.css);
298
+ }
299
+ const elapsed = (performance.now() - startTime).toFixed(2);
300
+ logger.info(`Pre-compilation complete: ${result.successCount} succeeded, ${result.failedCount} failed (${elapsed}ms, native batch: ${result.timeMs.toFixed(2)}ms)`);
301
+ }
302
+ function resolveVuePath(id, importer) {
303
+ let resolved;
304
+ if (id.startsWith("/@fs/")) resolved = id.slice(4);
305
+ else if (id.startsWith("/") && !fs.existsSync(id)) resolved = path.resolve(root, id.slice(1));
306
+ else if (path.isAbsolute(id)) resolved = id;
307
+ else if (importer) {
308
+ let realImporter = importer.startsWith(VIRTUAL_PREFIX) ? virtualToReal.get(importer) ?? importer.slice(VIRTUAL_PREFIX.length) : importer;
309
+ if (realImporter.endsWith(".vue.ts")) realImporter = realImporter.slice(0, -3);
310
+ resolved = path.resolve(path.dirname(realImporter), id);
311
+ } else resolved = path.resolve(root, id);
312
+ if (!path.isAbsolute(resolved)) resolved = path.resolve(root, resolved);
313
+ return path.normalize(resolved);
314
+ }
315
+ return {
316
+ name: "vite-plugin-vize",
317
+ enforce: "pre",
318
+ config() {
319
+ return { optimizeDeps: {
320
+ include: ["vue"],
321
+ exclude: ["virtual:vize-styles"],
322
+ esbuildOptions: { plugins: [{
323
+ name: "vize-externalize-vue",
324
+ setup(build) {
325
+ build.onResolve({ filter: /\.vue$/ }, (args) => ({
326
+ path: args.path,
327
+ external: true
328
+ }));
329
+ }
330
+ }] },
331
+ rolldownOptions: { external: [/\.vue$/] }
332
+ } };
333
+ },
334
+ async configResolved(resolvedConfig) {
335
+ root = options.root ?? resolvedConfig.root;
336
+ isProduction = options.isProduction ?? resolvedConfig.isProduction;
337
+ extractCss = isProduction;
338
+ const configEnv = {
339
+ mode: resolvedConfig.mode,
340
+ command: resolvedConfig.command === "build" ? "build" : "serve",
341
+ isSsrBuild: !!resolvedConfig.build?.ssr
342
+ };
343
+ let fileConfig = null;
344
+ if (options.configMode !== false) {
345
+ fileConfig = await loadConfig(root, {
346
+ mode: options.configMode ?? "root",
347
+ configFile: options.configFile,
348
+ env: configEnv
349
+ });
350
+ if (fileConfig) {
351
+ logger.log("Loaded config from vize.config file");
352
+ vizeConfigStore.set(root, fileConfig);
353
+ }
354
+ }
355
+ const viteConfig = fileConfig?.vite ?? {};
356
+ const compilerConfig = fileConfig?.compiler ?? {};
357
+ mergedOptions = {
358
+ ...options,
359
+ ssr: options.ssr ?? compilerConfig.ssr ?? false,
360
+ sourceMap: options.sourceMap ?? compilerConfig.sourceMap,
361
+ vapor: options.vapor ?? compilerConfig.vapor ?? false,
362
+ include: options.include ?? viteConfig.include,
363
+ exclude: options.exclude ?? viteConfig.exclude,
364
+ scanPatterns: options.scanPatterns ?? viteConfig.scanPatterns,
365
+ ignorePatterns: options.ignorePatterns ?? viteConfig.ignorePatterns
366
+ };
367
+ filter = createFilter(mergedOptions.include, mergedOptions.exclude);
368
+ scanPatterns = mergedOptions.scanPatterns ?? ["**/*.vue"];
369
+ ignorePatterns = mergedOptions.ignorePatterns ?? [
370
+ "node_modules/**",
371
+ "dist/**",
372
+ ".git/**"
373
+ ];
374
+ },
375
+ configureServer(devServer) {
376
+ server = devServer;
377
+ },
378
+ async buildStart() {
379
+ await compileAll();
380
+ logger.log("Cache keys:", [...cache.keys()].slice(0, 3));
381
+ },
382
+ async resolveId(id, importer) {
383
+ if (id.startsWith("\0")) return null;
384
+ if (id.startsWith("vize:")) {
385
+ let realPath = id.slice(5);
386
+ if (realPath.endsWith(".ts")) realPath = realPath.slice(0, -3);
387
+ logger.log(`resolveId: redirecting stale vize: ID to ${realPath}`);
388
+ if (realPath.includes("node_modules")) return realPath;
389
+ return this.resolve(realPath, importer, { skipSelf: true });
390
+ }
391
+ if (id === VIRTUAL_CSS_MODULE) return RESOLVED_CSS_MODULE;
392
+ if (id.includes("?vue&type=style")) return id;
393
+ if (importer?.startsWith(VIRTUAL_PREFIX)) {
394
+ const realImporter = virtualToReal.get(importer) ?? importer.slice(VIRTUAL_PREFIX.length);
395
+ const cleanImporter = realImporter.endsWith(".ts") ? realImporter.slice(0, -3) : realImporter;
396
+ logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
397
+ if (!id.endsWith(".vue")) if (id.startsWith("./") || id.startsWith("../")) {
398
+ const [pathPart, queryPart] = id.split("?");
399
+ const querySuffix = queryPart ? `?${queryPart}` : "";
400
+ const resolved = path.resolve(path.dirname(cleanImporter), pathPart);
401
+ for (const ext of [
402
+ "",
403
+ ".ts",
404
+ ".tsx",
405
+ ".js",
406
+ ".jsx",
407
+ ".json"
408
+ ]) if (fs.existsSync(resolved + ext)) {
409
+ const finalPath = resolved + ext + querySuffix;
410
+ logger.log(`resolveId: resolved relative ${id} to ${finalPath}`);
411
+ return finalPath;
412
+ }
413
+ } else {
414
+ if (id.includes("/dist/") || id.includes("/lib/") || id.includes("/es/")) {
415
+ logger.log(`resolveId: skipping already-resolved path ${id}`);
416
+ return null;
417
+ }
418
+ logger.log(`resolveId: resolving external ${id} from ${cleanImporter}`);
419
+ const resolved = await this.resolve(id, cleanImporter, { skipSelf: true });
420
+ logger.log(`resolveId: resolved external ${id} to`, resolved?.id ?? "null");
421
+ return resolved;
422
+ }
423
+ }
424
+ if (id.endsWith(".vue")) {
425
+ if (id.includes("node_modules")) {
426
+ logger.log(`resolveId: skipping node_modules import ${id}`);
427
+ return null;
428
+ }
429
+ const resolved = resolveVuePath(id, importer);
430
+ if (resolved.includes("node_modules")) {
431
+ logger.log(`resolveId: skipping node_modules path ${resolved}`);
432
+ return null;
433
+ }
434
+ if (!filter(resolved)) {
435
+ logger.log(`resolveId: skipping filtered path ${resolved}`);
436
+ return null;
437
+ }
438
+ const hasCache = cache.has(resolved);
439
+ const fileExists = fs.existsSync(resolved);
440
+ logger.log(`resolveId: id=${id}, resolved=${resolved}, hasCache=${hasCache}, fileExists=${fileExists}, importer=${importer ?? "none"}`);
441
+ if (hasCache || fileExists) {
442
+ const virtualId = VIRTUAL_PREFIX + resolved + ".ts";
443
+ virtualToReal.set(virtualId, resolved);
444
+ return virtualId;
445
+ }
446
+ }
447
+ return null;
448
+ },
449
+ load(id) {
450
+ if (id === RESOLVED_CSS_MODULE) {
451
+ const allCss = Array.from(collectedCss.values()).join("\n\n");
452
+ return allCss;
453
+ }
454
+ if (id.includes("?vue&type=style")) {
455
+ const [filename] = id.split("?");
456
+ const realPath = filename.startsWith(VIRTUAL_PREFIX) ? virtualToReal.get(filename) ?? filename.slice(VIRTUAL_PREFIX.length) : filename;
457
+ const compiled = cache.get(realPath);
458
+ if (compiled?.css) return compiled.css;
459
+ return "";
460
+ }
461
+ if (id.startsWith(VIRTUAL_PREFIX)) {
462
+ const lookupId = id.endsWith(".ts") ? id.slice(0, -3) : id;
463
+ const realPath = virtualToReal.get(id) ?? lookupId.slice(VIRTUAL_PREFIX.length);
464
+ const compiled = cache.get(realPath);
465
+ if (compiled) {
466
+ const output = generateOutput(compiled, {
467
+ isProduction,
468
+ isDev: server !== null,
469
+ extractCss
470
+ });
471
+ return {
472
+ code: output,
473
+ map: null
474
+ };
475
+ }
476
+ }
477
+ return null;
478
+ },
479
+ async transform(code, id) {
480
+ if (id.startsWith(VIRTUAL_PREFIX) && id.endsWith(".ts")) {
481
+ const result = await transformWithOxc(code, id.slice(VIRTUAL_PREFIX.length), { lang: "ts" });
482
+ return {
483
+ code: result.code,
484
+ map: result.map
485
+ };
486
+ }
487
+ return null;
488
+ },
489
+ async handleHotUpdate(ctx) {
490
+ const { file, server: server$1, read } = ctx;
491
+ if (file.endsWith(".vue") && filter(file)) try {
492
+ const source = await read();
493
+ const prevCompiled = cache.get(file);
494
+ compileFile(file, cache, {
495
+ sourceMap: mergedOptions.sourceMap ?? !isProduction,
496
+ ssr: mergedOptions.ssr ?? false
497
+ }, source);
498
+ const newCompiled = cache.get(file);
499
+ const updateType = detectHmrUpdateType(prevCompiled, newCompiled);
500
+ logger.log(`Re-compiled: ${path.relative(root, file)} (${updateType})`);
501
+ const virtualId = VIRTUAL_PREFIX + file + ".ts";
502
+ const modules = server$1.moduleGraph.getModulesByFile(virtualId) ?? server$1.moduleGraph.getModulesByFile(file);
503
+ if (updateType === "style-only" && newCompiled.css) {
504
+ server$1.ws.send({
505
+ type: "custom",
506
+ event: "vize:update",
507
+ data: {
508
+ id: newCompiled.scopeId,
509
+ type: "style-only",
510
+ css: newCompiled.css
511
+ }
512
+ });
513
+ return [];
514
+ }
515
+ if (modules) return [...modules];
516
+ } catch (e) {
517
+ logger.error(`Re-compilation failed for ${file}:`, e);
518
+ }
519
+ },
520
+ generateBundle(_, _bundle) {
521
+ if (!extractCss || collectedCss.size === 0) return;
522
+ const allCss = Array.from(collectedCss.values()).join("\n\n");
523
+ if (allCss.trim()) {
524
+ this.emitFile({
525
+ type: "asset",
526
+ fileName: "assets/vize-components.css",
527
+ source: allCss
528
+ });
529
+ logger.log(`Extracted CSS to assets/vize-components.css (${collectedCss.size} components)`);
530
+ }
531
+ }
532
+ };
140
533
  }
141
- export default vize;
534
+ var src_default = vize;
535
+
536
+ //#endregion
537
+ export { src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };