@vizejs/vite-plugin 0.0.1-alpha.100 → 0.0.1-alpha.102
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.ts +25 -2
- package/dist/index.js +284 -72
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -459,6 +459,14 @@ interface VizeOptions {
|
|
|
459
459
|
* Custom config file path (overrides automatic search)
|
|
460
460
|
*/
|
|
461
461
|
configFile?: string;
|
|
462
|
+
/**
|
|
463
|
+
* Handle .vue files in node_modules (on-demand compilation).
|
|
464
|
+
* When true, vize will compile .vue files from node_modules that other plugins
|
|
465
|
+
* (like vite-plugin-vue-inspector) may import directly.
|
|
466
|
+
* Set to false if another Vue plugin (e.g. Nuxt) handles node_modules .vue files.
|
|
467
|
+
* @default true
|
|
468
|
+
*/
|
|
469
|
+
handleNodeModulesVue?: boolean;
|
|
462
470
|
/**
|
|
463
471
|
* Enable debug logging
|
|
464
472
|
* @default false
|
|
@@ -492,7 +500,22 @@ declare function loadConfig(root: string, options?: LoadConfigOptions): Promise<
|
|
|
492
500
|
* Used by musea() and other plugins to access the unified config.
|
|
493
501
|
*/
|
|
494
502
|
declare const vizeConfigStore: Map<string, VizeConfig>;
|
|
495
|
-
|
|
503
|
+
interface DynamicImportAliasRule {
|
|
504
|
+
fromPrefix: string;
|
|
505
|
+
toPrefix: string;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Rewrite static asset URLs in compiled template output.
|
|
509
|
+
*
|
|
510
|
+
* Transforms property values like `src: "@/assets/logo.svg"` into import
|
|
511
|
+
* statements hoisted to the top of the module, so Vite's module resolution
|
|
512
|
+
* pipeline handles alias expansion and asset hashing in both dev and build.
|
|
513
|
+
*/
|
|
514
|
+
declare function rewriteStaticAssetUrls(code: string, aliasRules: DynamicImportAliasRule[]): string;
|
|
515
|
+
declare const __internal: {
|
|
516
|
+
rewriteStaticAssetUrls: typeof rewriteStaticAssetUrls;
|
|
517
|
+
};
|
|
518
|
+
declare function vize(options?: VizeOptions): Plugin[];
|
|
496
519
|
|
|
497
520
|
//#endregion
|
|
498
|
-
export { CompiledModule, LoadConfigOptions, VizeConfig, VizeOptions, vize as default, defineConfig, loadConfig, vize, vizeConfigStore };
|
|
521
|
+
export { CompiledModule, LoadConfigOptions, VizeConfig, VizeOptions, __internal, vize as default, defineConfig, loadConfig, vize, vizeConfigStore };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { transformWithOxc } from "vite";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
4
6
|
import { glob } from "tinyglobby";
|
|
5
7
|
import * as native from "@vizejs/native";
|
|
6
8
|
import { createHash } from "node:crypto";
|
|
@@ -250,9 +252,69 @@ async function loadConfigFile(configPath, env) {
|
|
|
250
252
|
* Used by musea() and other plugins to access the unified config.
|
|
251
253
|
*/
|
|
252
254
|
const vizeConfigStore = new Map();
|
|
253
|
-
const
|
|
255
|
+
const LEGACY_VIZE_PREFIX = "\0vize:";
|
|
254
256
|
const VIRTUAL_CSS_MODULE = "virtual:vize-styles";
|
|
255
257
|
const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
|
|
258
|
+
/** Check if a module ID is a vize-compiled virtual module */
|
|
259
|
+
function isVizeVirtual(id) {
|
|
260
|
+
return id.startsWith("\0") && id.endsWith(".vue.ts");
|
|
261
|
+
}
|
|
262
|
+
/** Create a virtual module ID from a real .vue file path */
|
|
263
|
+
function toVirtualId(realPath) {
|
|
264
|
+
return "\0" + realPath + ".ts";
|
|
265
|
+
}
|
|
266
|
+
/** Extract the real .vue file path from a virtual module ID */
|
|
267
|
+
function fromVirtualId(virtualId) {
|
|
268
|
+
return virtualId.slice(1, -3);
|
|
269
|
+
}
|
|
270
|
+
function escapeRegExp(value) {
|
|
271
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
272
|
+
}
|
|
273
|
+
function toBrowserImportPrefix(replacement) {
|
|
274
|
+
const normalized = replacement.replace(/\\/g, "/");
|
|
275
|
+
if (normalized.startsWith("/@fs/")) return normalized;
|
|
276
|
+
if (path.isAbsolute(replacement) && fs.existsSync(replacement)) return `/@fs${normalized}`;
|
|
277
|
+
return normalized;
|
|
278
|
+
}
|
|
279
|
+
function normalizeFsIdForBuild(id) {
|
|
280
|
+
const [pathPart, queryPart] = id.split("?");
|
|
281
|
+
if (!pathPart.startsWith("/@fs/")) return id;
|
|
282
|
+
const normalizedPath = pathPart.slice(4);
|
|
283
|
+
return queryPart ? `${normalizedPath}?${queryPart}` : normalizedPath;
|
|
284
|
+
}
|
|
285
|
+
function rewriteDynamicTemplateImports(code, aliasRules) {
|
|
286
|
+
let rewritten = code;
|
|
287
|
+
for (const rule of aliasRules) {
|
|
288
|
+
const pattern = new RegExp(`\\bimport\\s*\\(\\s*\`${escapeRegExp(rule.fromPrefix)}`, "g");
|
|
289
|
+
rewritten = rewritten.replace(pattern, `import(/* @vite-ignore */ \`${rule.toPrefix}`);
|
|
290
|
+
}
|
|
291
|
+
rewritten = rewritten.replace(/\bimport\s*\(\s*`/g, "import(/* @vite-ignore */ `");
|
|
292
|
+
return rewritten;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Rewrite static asset URLs in compiled template output.
|
|
296
|
+
*
|
|
297
|
+
* Transforms property values like `src: "@/assets/logo.svg"` into import
|
|
298
|
+
* statements hoisted to the top of the module, so Vite's module resolution
|
|
299
|
+
* pipeline handles alias expansion and asset hashing in both dev and build.
|
|
300
|
+
*/
|
|
301
|
+
function rewriteStaticAssetUrls(code, aliasRules) {
|
|
302
|
+
let rewritten = code;
|
|
303
|
+
const imports = [];
|
|
304
|
+
let counter = 0;
|
|
305
|
+
for (const rule of aliasRules) {
|
|
306
|
+
const pattern = new RegExp(`("?src"?\\s*:\\s*)(?:"(${escapeRegExp(rule.fromPrefix)}[^"]+)"|'(${escapeRegExp(rule.fromPrefix)}[^']+)')`, "g");
|
|
307
|
+
rewritten = rewritten.replace(pattern, (_match, prefix, dqPath, sqPath) => {
|
|
308
|
+
const fullPath = dqPath || sqPath;
|
|
309
|
+
const varName = `__vize_static_${counter++}`;
|
|
310
|
+
imports.push(`import ${varName} from ${JSON.stringify(fullPath)};`);
|
|
311
|
+
return `${prefix}${varName}`;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (imports.length > 0) rewritten = imports.join("\n") + "\n" + rewritten;
|
|
315
|
+
return rewritten;
|
|
316
|
+
}
|
|
317
|
+
const __internal = { rewriteStaticAssetUrls };
|
|
256
318
|
function createLogger(debug) {
|
|
257
319
|
return {
|
|
258
320
|
log: (...args) => debug && console.log("[vize]", ...args),
|
|
@@ -263,7 +325,6 @@ function createLogger(debug) {
|
|
|
263
325
|
}
|
|
264
326
|
function vize(options = {}) {
|
|
265
327
|
const cache = new Map();
|
|
266
|
-
const virtualToReal = new Map();
|
|
267
328
|
const collectedCss = new Map();
|
|
268
329
|
let isProduction;
|
|
269
330
|
let root;
|
|
@@ -272,6 +333,7 @@ function vize(options = {}) {
|
|
|
272
333
|
let scanPatterns;
|
|
273
334
|
let ignorePatterns;
|
|
274
335
|
let mergedOptions;
|
|
336
|
+
let dynamicImportAliasRules = [];
|
|
275
337
|
let extractCss = false;
|
|
276
338
|
const logger = createLogger(options.debug ?? false);
|
|
277
339
|
async function compileAll() {
|
|
@@ -305,31 +367,37 @@ function vize(options = {}) {
|
|
|
305
367
|
else if (id.startsWith("/") && !fs.existsSync(id)) resolved = path.resolve(root, id.slice(1));
|
|
306
368
|
else if (path.isAbsolute(id)) resolved = id;
|
|
307
369
|
else if (importer) {
|
|
308
|
-
|
|
309
|
-
if (realImporter.endsWith(".vue.ts")) realImporter = realImporter.slice(0, -3);
|
|
370
|
+
const realImporter = isVizeVirtual(importer) ? fromVirtualId(importer) : importer;
|
|
310
371
|
resolved = path.resolve(path.dirname(realImporter), id);
|
|
311
372
|
} else resolved = path.resolve(root, id);
|
|
312
373
|
if (!path.isAbsolute(resolved)) resolved = path.resolve(root, resolved);
|
|
313
374
|
return path.normalize(resolved);
|
|
314
375
|
}
|
|
315
|
-
|
|
376
|
+
const mainPlugin = {
|
|
316
377
|
name: "vite-plugin-vize",
|
|
317
378
|
enforce: "pre",
|
|
318
|
-
config() {
|
|
319
|
-
return {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
379
|
+
config(_, env) {
|
|
380
|
+
return {
|
|
381
|
+
define: {
|
|
382
|
+
__VUE_OPTIONS_API__: true,
|
|
383
|
+
__VUE_PROD_DEVTOOLS__: env.command === "serve",
|
|
384
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
|
|
385
|
+
},
|
|
386
|
+
optimizeDeps: {
|
|
387
|
+
include: ["vue"],
|
|
388
|
+
exclude: ["virtual:vize-styles"],
|
|
389
|
+
esbuildOptions: { plugins: [{
|
|
390
|
+
name: "vize-externalize-vue",
|
|
391
|
+
setup(build) {
|
|
392
|
+
build.onResolve({ filter: /\.vue$/ }, (args) => ({
|
|
393
|
+
path: args.path,
|
|
394
|
+
external: true
|
|
395
|
+
}));
|
|
396
|
+
}
|
|
397
|
+
}] },
|
|
398
|
+
rolldownOptions: { external: [/\.vue$/] }
|
|
399
|
+
}
|
|
400
|
+
};
|
|
333
401
|
},
|
|
334
402
|
async configResolved(resolvedConfig) {
|
|
335
403
|
root = options.root ?? resolvedConfig.root;
|
|
@@ -364,6 +432,18 @@ function vize(options = {}) {
|
|
|
364
432
|
scanPatterns: options.scanPatterns ?? viteConfig.scanPatterns,
|
|
365
433
|
ignorePatterns: options.ignorePatterns ?? viteConfig.ignorePatterns
|
|
366
434
|
};
|
|
435
|
+
dynamicImportAliasRules = [];
|
|
436
|
+
for (const alias of resolvedConfig.resolve.alias) {
|
|
437
|
+
if (typeof alias.find !== "string" || typeof alias.replacement !== "string") continue;
|
|
438
|
+
const fromPrefix = alias.find.endsWith("/") ? alias.find : `${alias.find}/`;
|
|
439
|
+
const replacement = toBrowserImportPrefix(alias.replacement);
|
|
440
|
+
const toPrefix = replacement.endsWith("/") ? replacement : `${replacement}/`;
|
|
441
|
+
dynamicImportAliasRules.push({
|
|
442
|
+
fromPrefix,
|
|
443
|
+
toPrefix
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
dynamicImportAliasRules.sort((a, b) => b.fromPrefix.length - a.fromPrefix.length);
|
|
367
447
|
filter = createFilter(mergedOptions.include, mergedOptions.exclude);
|
|
368
448
|
scanPatterns = mergedOptions.scanPatterns ?? ["**/*.vue"];
|
|
369
449
|
ignorePatterns = mergedOptions.ignorePatterns ?? [
|
|
@@ -374,79 +454,152 @@ function vize(options = {}) {
|
|
|
374
454
|
},
|
|
375
455
|
configureServer(devServer) {
|
|
376
456
|
server = devServer;
|
|
457
|
+
devServer.middlewares.use((req, _res, next) => {
|
|
458
|
+
if (req.url && req.url.includes("__x00__")) {
|
|
459
|
+
const [urlPath, queryPart] = req.url.split("?");
|
|
460
|
+
let cleanedPath = urlPath.replace(/__x00__/g, "");
|
|
461
|
+
cleanedPath = cleanedPath.replace(/^\/@id\/\//, "/@fs/");
|
|
462
|
+
if (cleanedPath.startsWith("/@fs/")) {
|
|
463
|
+
const fsPath = cleanedPath.slice(4);
|
|
464
|
+
if (fsPath.startsWith("/") && fs.existsSync(fsPath) && fs.statSync(fsPath).isFile() && !fsPath.endsWith(".vue.ts")) {
|
|
465
|
+
const cleaned = queryPart ? `${cleanedPath}?${queryPart}` : cleanedPath;
|
|
466
|
+
if (cleaned !== req.url) {
|
|
467
|
+
logger.log(`middleware: rewriting ${req.url} → ${cleaned}`);
|
|
468
|
+
req.url = cleaned;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
next();
|
|
474
|
+
});
|
|
377
475
|
},
|
|
378
476
|
async buildStart() {
|
|
379
477
|
await compileAll();
|
|
380
478
|
logger.log("Cache keys:", [...cache.keys()].slice(0, 3));
|
|
381
479
|
},
|
|
382
480
|
async resolveId(id, importer) {
|
|
383
|
-
|
|
481
|
+
const isBuild = server === null;
|
|
482
|
+
if (id.startsWith("\0")) {
|
|
483
|
+
if (isVizeVirtual(id)) return null;
|
|
484
|
+
if (id.startsWith(LEGACY_VIZE_PREFIX)) {
|
|
485
|
+
const rawPath = id.slice(LEGACY_VIZE_PREFIX.length);
|
|
486
|
+
const cleanPath$1 = rawPath.endsWith(".ts") ? rawPath.slice(0, -3) : rawPath;
|
|
487
|
+
if (!cleanPath$1.endsWith(".vue")) {
|
|
488
|
+
logger.log(`resolveId: redirecting legacy virtual ID to ${cleanPath$1}`);
|
|
489
|
+
return cleanPath$1;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const cleanPath = id.slice(1);
|
|
493
|
+
if (cleanPath.startsWith("/") && !cleanPath.endsWith(".vue.ts")) {
|
|
494
|
+
const [pathPart, queryPart] = cleanPath.split("?");
|
|
495
|
+
const querySuffix = queryPart ? `?${queryPart}` : "";
|
|
496
|
+
logger.log(`resolveId: redirecting \0-prefixed non-vue ID to ${pathPart}${querySuffix}`);
|
|
497
|
+
const redirected = pathPart + querySuffix;
|
|
498
|
+
return isBuild ? normalizeFsIdForBuild(redirected) : redirected;
|
|
499
|
+
}
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
384
502
|
if (id.startsWith("vize:")) {
|
|
385
503
|
let realPath = id.slice(5);
|
|
386
504
|
if (realPath.endsWith(".ts")) realPath = realPath.slice(0, -3);
|
|
387
505
|
logger.log(`resolveId: redirecting stale vize: ID to ${realPath}`);
|
|
388
|
-
|
|
389
|
-
|
|
506
|
+
const resolved = await this.resolve(realPath, importer, { skipSelf: true });
|
|
507
|
+
if (resolved && isBuild && resolved.id.startsWith("/@fs/")) return {
|
|
508
|
+
...resolved,
|
|
509
|
+
id: normalizeFsIdForBuild(resolved.id)
|
|
510
|
+
};
|
|
511
|
+
return resolved;
|
|
390
512
|
}
|
|
391
513
|
if (id === VIRTUAL_CSS_MODULE) return RESOLVED_CSS_MODULE;
|
|
514
|
+
if (isBuild && id.startsWith("/@fs/")) return normalizeFsIdForBuild(id);
|
|
392
515
|
if (id.includes("?vue&type=style")) return id;
|
|
393
|
-
if (importer
|
|
394
|
-
const
|
|
395
|
-
const cleanImporter = realImporter.endsWith(".ts") ? realImporter.slice(0, -3) : realImporter;
|
|
516
|
+
if (importer && isVizeVirtual(importer)) {
|
|
517
|
+
const cleanImporter = fromVirtualId(importer);
|
|
396
518
|
logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
|
|
397
519
|
if (id.startsWith("#")) try {
|
|
398
520
|
return await this.resolve(id, cleanImporter, { skipSelf: true });
|
|
399
521
|
} catch {
|
|
400
522
|
return null;
|
|
401
523
|
}
|
|
402
|
-
if (!id.endsWith(".vue"))
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
524
|
+
if (!id.endsWith(".vue")) {
|
|
525
|
+
if (id.includes("/dist/") || id.includes("/lib/") || id.includes("/es/")) return null;
|
|
526
|
+
try {
|
|
527
|
+
const resolved = await this.resolve(id, cleanImporter, { skipSelf: true });
|
|
528
|
+
if (resolved) {
|
|
529
|
+
logger.log(`resolveId: resolved ${id} to ${resolved.id} via Vite resolver`);
|
|
530
|
+
if (isBuild && resolved.id.startsWith("/@fs/")) return {
|
|
531
|
+
...resolved,
|
|
532
|
+
id: normalizeFsIdForBuild(resolved.id)
|
|
533
|
+
};
|
|
534
|
+
return resolved;
|
|
535
|
+
}
|
|
536
|
+
} catch {}
|
|
537
|
+
if (id.startsWith("./") || id.startsWith("../")) {
|
|
538
|
+
const [pathPart, queryPart] = id.split("?");
|
|
539
|
+
const querySuffix = queryPart ? `?${queryPart}` : "";
|
|
540
|
+
const resolved = path.resolve(path.dirname(cleanImporter), pathPart);
|
|
541
|
+
for (const ext of [
|
|
542
|
+
"",
|
|
543
|
+
".ts",
|
|
544
|
+
".tsx",
|
|
545
|
+
".js",
|
|
546
|
+
".jsx",
|
|
547
|
+
".json"
|
|
548
|
+
]) {
|
|
549
|
+
const candidate = resolved + ext;
|
|
550
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
551
|
+
const finalPath = candidate + querySuffix;
|
|
552
|
+
logger.log(`resolveId: resolved relative ${id} to ${finalPath}`);
|
|
553
|
+
return finalPath;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) for (const indexFile of [
|
|
557
|
+
"/index.ts",
|
|
558
|
+
"/index.tsx",
|
|
559
|
+
"/index.js",
|
|
560
|
+
"/index.jsx"
|
|
561
|
+
]) {
|
|
562
|
+
const candidate = resolved + indexFile;
|
|
563
|
+
if (fs.existsSync(candidate)) {
|
|
564
|
+
const finalPath = candidate + querySuffix;
|
|
565
|
+
logger.log(`resolveId: resolved directory ${id} to ${finalPath}`);
|
|
566
|
+
return finalPath;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
422
569
|
}
|
|
423
|
-
|
|
424
|
-
const resolved = await this.resolve(id, cleanImporter, { skipSelf: true });
|
|
425
|
-
logger.log(`resolveId: resolved external ${id} to`, resolved?.id ?? "null");
|
|
426
|
-
return resolved;
|
|
570
|
+
return null;
|
|
427
571
|
}
|
|
428
572
|
}
|
|
429
573
|
if (id.endsWith(".vue")) {
|
|
430
|
-
|
|
574
|
+
const handleNodeModules = mergedOptions.handleNodeModulesVue ?? true;
|
|
575
|
+
if (!handleNodeModules && id.includes("node_modules")) {
|
|
431
576
|
logger.log(`resolveId: skipping node_modules import ${id}`);
|
|
432
577
|
return null;
|
|
433
578
|
}
|
|
434
579
|
const resolved = resolveVuePath(id, importer);
|
|
435
|
-
|
|
580
|
+
const isNodeModulesPath = resolved.includes("node_modules");
|
|
581
|
+
if (!handleNodeModules && isNodeModulesPath) {
|
|
436
582
|
logger.log(`resolveId: skipping node_modules path ${resolved}`);
|
|
437
583
|
return null;
|
|
438
584
|
}
|
|
439
|
-
if (!filter(resolved)) {
|
|
585
|
+
if (!isNodeModulesPath && !filter(resolved)) {
|
|
440
586
|
logger.log(`resolveId: skipping filtered path ${resolved}`);
|
|
441
587
|
return null;
|
|
442
588
|
}
|
|
443
589
|
const hasCache = cache.has(resolved);
|
|
444
590
|
const fileExists = fs.existsSync(resolved);
|
|
445
591
|
logger.log(`resolveId: id=${id}, resolved=${resolved}, hasCache=${hasCache}, fileExists=${fileExists}, importer=${importer ?? "none"}`);
|
|
446
|
-
if (hasCache || fileExists)
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
592
|
+
if (hasCache || fileExists) return toVirtualId(resolved);
|
|
593
|
+
if (!fileExists && !path.isAbsolute(id)) {
|
|
594
|
+
const viteResolved = await this.resolve(id, importer, { skipSelf: true });
|
|
595
|
+
if (viteResolved && viteResolved.id.endsWith(".vue")) {
|
|
596
|
+
const realPath = viteResolved.id;
|
|
597
|
+
const isResolvedNodeModules = realPath.includes("node_modules");
|
|
598
|
+
if ((isResolvedNodeModules ? handleNodeModules : filter(realPath)) && (cache.has(realPath) || fs.existsSync(realPath))) {
|
|
599
|
+
logger.log(`resolveId: resolved via Vite fallback ${id} to ${realPath}`);
|
|
600
|
+
return toVirtualId(realPath);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
450
603
|
}
|
|
451
604
|
}
|
|
452
605
|
return null;
|
|
@@ -458,36 +611,70 @@ function vize(options = {}) {
|
|
|
458
611
|
}
|
|
459
612
|
if (id.includes("?vue&type=style")) {
|
|
460
613
|
const [filename] = id.split("?");
|
|
461
|
-
const realPath = filename
|
|
614
|
+
const realPath = isVizeVirtual(filename) ? fromVirtualId(filename) : filename;
|
|
462
615
|
const compiled = cache.get(realPath);
|
|
463
616
|
if (compiled?.css) return compiled.css;
|
|
464
617
|
return "";
|
|
465
618
|
}
|
|
466
|
-
if (id
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
619
|
+
if (isVizeVirtual(id)) {
|
|
620
|
+
const realPath = fromVirtualId(id);
|
|
621
|
+
if (!realPath.endsWith(".vue")) {
|
|
622
|
+
logger.log(`load: skipping non-vue virtual module ${realPath}`);
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
625
|
+
let compiled = cache.get(realPath);
|
|
626
|
+
if (!compiled && fs.existsSync(realPath)) {
|
|
627
|
+
logger.log(`load: on-demand compiling ${realPath}`);
|
|
628
|
+
compiled = compileFile(realPath, cache, {
|
|
629
|
+
sourceMap: mergedOptions.sourceMap ?? !isProduction,
|
|
630
|
+
ssr: mergedOptions.ssr ?? false
|
|
631
|
+
});
|
|
632
|
+
}
|
|
470
633
|
if (compiled) {
|
|
471
|
-
const output = generateOutput(compiled, {
|
|
634
|
+
const output = rewriteStaticAssetUrls(rewriteDynamicTemplateImports(generateOutput(compiled, {
|
|
472
635
|
isProduction,
|
|
473
636
|
isDev: server !== null,
|
|
474
637
|
extractCss
|
|
475
|
-
});
|
|
638
|
+
}), dynamicImportAliasRules), dynamicImportAliasRules);
|
|
476
639
|
return {
|
|
477
640
|
code: output,
|
|
478
641
|
map: null
|
|
479
642
|
};
|
|
480
643
|
}
|
|
481
644
|
}
|
|
645
|
+
if (id.startsWith("\0")) {
|
|
646
|
+
const afterPrefix = id.startsWith(LEGACY_VIZE_PREFIX) ? id.slice(LEGACY_VIZE_PREFIX.length) : id.slice(1);
|
|
647
|
+
if (afterPrefix.includes("?commonjs-")) return null;
|
|
648
|
+
const [pathPart, queryPart] = afterPrefix.split("?");
|
|
649
|
+
const querySuffix = queryPart ? `?${queryPart}` : "";
|
|
650
|
+
const fsPath = pathPart.startsWith("/@fs/") ? pathPart.slice(4) : pathPart;
|
|
651
|
+
if (fsPath.startsWith("/") && fs.existsSync(fsPath) && fs.statSync(fsPath).isFile()) {
|
|
652
|
+
const importPath = server === null ? `${pathToFileURL(fsPath).href}${querySuffix}` : "/@fs" + fsPath + querySuffix;
|
|
653
|
+
logger.log(`load: proxying \0-prefixed file ${id} → re-export from ${importPath}`);
|
|
654
|
+
return `export { default } from ${JSON.stringify(importPath)};\nexport * from ${JSON.stringify(importPath)};`;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
482
657
|
return null;
|
|
483
658
|
},
|
|
484
659
|
async transform(code, id) {
|
|
485
|
-
if (
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
660
|
+
if (isVizeVirtual(id)) {
|
|
661
|
+
const realPath = fromVirtualId(id);
|
|
662
|
+
try {
|
|
663
|
+
const result = await transformWithOxc(code, realPath, { lang: "ts" });
|
|
664
|
+
return {
|
|
665
|
+
code: result.code,
|
|
666
|
+
map: result.map
|
|
667
|
+
};
|
|
668
|
+
} catch (e) {
|
|
669
|
+
logger.error(`transformWithOxc failed for ${realPath}:`, e);
|
|
670
|
+
const dumpPath = `/tmp/vize-oxc-error-${path.basename(realPath)}.ts`;
|
|
671
|
+
fs.writeFileSync(dumpPath, code, "utf-8");
|
|
672
|
+
logger.error(`Dumped failing code to ${dumpPath}`);
|
|
673
|
+
return {
|
|
674
|
+
code: "export default {}",
|
|
675
|
+
map: null
|
|
676
|
+
};
|
|
677
|
+
}
|
|
491
678
|
}
|
|
492
679
|
return null;
|
|
493
680
|
},
|
|
@@ -503,7 +690,7 @@ function vize(options = {}) {
|
|
|
503
690
|
const newCompiled = cache.get(file);
|
|
504
691
|
const updateType = detectHmrUpdateType(prevCompiled, newCompiled);
|
|
505
692
|
logger.log(`Re-compiled: ${path.relative(root, file)} (${updateType})`);
|
|
506
|
-
const virtualId =
|
|
693
|
+
const virtualId = toVirtualId(file);
|
|
507
694
|
const modules = server$1.moduleGraph.getModulesByFile(virtualId) ?? server$1.moduleGraph.getModulesByFile(file);
|
|
508
695
|
if (updateType === "style-only" && newCompiled.css) {
|
|
509
696
|
server$1.ws.send({
|
|
@@ -535,8 +722,33 @@ function vize(options = {}) {
|
|
|
535
722
|
}
|
|
536
723
|
}
|
|
537
724
|
};
|
|
725
|
+
let compilerSfc = null;
|
|
726
|
+
const loadCompilerSfc = () => {
|
|
727
|
+
if (!compilerSfc) try {
|
|
728
|
+
const require = createRequire(import.meta.url);
|
|
729
|
+
compilerSfc = require("@vue/compiler-sfc");
|
|
730
|
+
} catch {
|
|
731
|
+
compilerSfc = { parse: () => ({
|
|
732
|
+
descriptor: {},
|
|
733
|
+
errors: []
|
|
734
|
+
}) };
|
|
735
|
+
}
|
|
736
|
+
return compilerSfc;
|
|
737
|
+
};
|
|
738
|
+
const vueCompatPlugin = {
|
|
739
|
+
name: "vite:vue",
|
|
740
|
+
api: { get options() {
|
|
741
|
+
return {
|
|
742
|
+
compiler: loadCompilerSfc(),
|
|
743
|
+
isProduction: isProduction ?? false,
|
|
744
|
+
root: root ?? process.cwd(),
|
|
745
|
+
template: {}
|
|
746
|
+
};
|
|
747
|
+
} }
|
|
748
|
+
};
|
|
749
|
+
return [vueCompatPlugin, mainPlugin];
|
|
538
750
|
}
|
|
539
751
|
var src_default = vize;
|
|
540
752
|
|
|
541
753
|
//#endregion
|
|
542
|
-
export { src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };
|
|
754
|
+
export { __internal, src_default as default, defineConfig, loadConfig, vize, vizeConfigStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.102",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"tinyglobby": "^0.2.0",
|
|
46
|
-
"@vizejs/native": "0.0.1-alpha.
|
|
46
|
+
"@vizejs/native": "0.0.1-alpha.102"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsdown",
|