@vizejs/vite-plugin 0.155.0 → 0.156.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +69 -20
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -137,7 +137,7 @@ function generateOutput(compiled, options) {
|
|
|
137
137
|
output += "\n_sfc_main.ssrRender = ssrRender;";
|
|
138
138
|
output += "\nexport default _sfc_main;";
|
|
139
139
|
}
|
|
140
|
-
if (hasDelegatedStyles(compiled) &&
|
|
140
|
+
if (!!filePath && !!compiled.styles?.length && (hasDelegatedStyles(compiled) || !ssr && isProduction && extractCss)) {
|
|
141
141
|
const styleImports = [];
|
|
142
142
|
const cssModuleImports = [];
|
|
143
143
|
for (const block of compiled.styles) {
|
|
@@ -395,6 +395,10 @@ function getCompileOptionsForRequest(state, ssr) {
|
|
|
395
395
|
}
|
|
396
396
|
function syncCollectedCssForFile(state, filePath, compiled) {
|
|
397
397
|
if (!compiled || !state.extractCss) return;
|
|
398
|
+
if (compiled.styles?.length) {
|
|
399
|
+
state.collectedCss.delete(filePath);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
398
402
|
if (compiled.css && !hasDelegatedStyles(compiled)) state.collectedCss.set(filePath, resolveCssImports(compiled.css, filePath, state.cssAliasRules, false));
|
|
399
403
|
else state.collectedCss.delete(filePath);
|
|
400
404
|
}
|
|
@@ -512,11 +516,37 @@ const EMPTY_NATIVE_ALIAS_RULES = [];
|
|
|
512
516
|
function resolveAliasRequest(state, id) {
|
|
513
517
|
return resolveViteAliasRequest(id, nativeCssAliasRules(state));
|
|
514
518
|
}
|
|
519
|
+
function getBarePackageName(id) {
|
|
520
|
+
if (!isViteBareSpecifier(id)) return null;
|
|
521
|
+
const segments = id.split("/");
|
|
522
|
+
if (id.startsWith("@")) return segments.length >= 2 ? `${segments[0]}/${segments[1]}` : null;
|
|
523
|
+
return segments[0] || null;
|
|
524
|
+
}
|
|
525
|
+
function resolveBareImportFromPnpmHoist(request, base) {
|
|
526
|
+
const packageName = getBarePackageName(request);
|
|
527
|
+
if (!packageName) return null;
|
|
528
|
+
let current = path.dirname(base);
|
|
529
|
+
while (current !== path.dirname(current)) {
|
|
530
|
+
const directPackage = path.join(current, "node_modules", packageName);
|
|
531
|
+
if (fs.existsSync(directPackage)) return null;
|
|
532
|
+
const hoistRoot = path.join(current, "node_modules", ".pnpm", "node_modules");
|
|
533
|
+
const hoistedPackage = path.join(hoistRoot, packageName);
|
|
534
|
+
if (fs.existsSync(hoistedPackage)) try {
|
|
535
|
+
return createRequire(path.join(hoistRoot, "__vize_probe__.js")).resolve(request);
|
|
536
|
+
} catch {}
|
|
537
|
+
current = path.dirname(current);
|
|
538
|
+
}
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
515
541
|
function resolveBareImportWithNode(state, id, importer) {
|
|
516
542
|
const { request, querySuffix } = splitViteIdQuery(id);
|
|
517
|
-
for (const candidate of createViteBareImportBases(state.root, importer))
|
|
518
|
-
|
|
519
|
-
|
|
543
|
+
for (const candidate of createViteBareImportBases(state.root, importer)) {
|
|
544
|
+
const hoisted = resolveBareImportFromPnpmHoist(request, candidate);
|
|
545
|
+
if (hoisted) return `${hoisted}${querySuffix}`;
|
|
546
|
+
try {
|
|
547
|
+
return `${createRequire(candidate).resolve(request)}${querySuffix}`;
|
|
548
|
+
} catch {}
|
|
549
|
+
}
|
|
520
550
|
return null;
|
|
521
551
|
}
|
|
522
552
|
function resolveBareImportCandidatesWithNode(state, id, importer, resolvedId) {
|
|
@@ -579,9 +609,8 @@ function isVueResolvableFromRoot(root) {
|
|
|
579
609
|
const directPackageJson = path.join(rootNodeModules, "vue", "package.json");
|
|
580
610
|
cached = fs.existsSync(directPackageJson);
|
|
581
611
|
if (!cached) try {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
cached = relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
612
|
+
createRequire(path.join(root, "__vize_probe__.js")).resolve("vue/package.json");
|
|
613
|
+
cached = true;
|
|
585
614
|
} catch {}
|
|
586
615
|
vueResolvableFromRootCache.set(root, cached);
|
|
587
616
|
}
|
|
@@ -597,7 +626,9 @@ function isPotentialVizeResolveId(id) {
|
|
|
597
626
|
return id.startsWith("\0") || id.startsWith("vize:") || id.startsWith("/@fs") || id === "virtual:vize-styles" || id.endsWith(".vue") || id.includes(".vue?") || id.includes("?macro=true") || id.includes("?definePage");
|
|
598
627
|
}
|
|
599
628
|
function isPotentialVizeImporter(importer) {
|
|
600
|
-
|
|
629
|
+
if (importer === void 0) return false;
|
|
630
|
+
if (importer.startsWith("\0") || importer.startsWith("vize:")) return true;
|
|
631
|
+
return classifyVitePluginRequest(importer).isVueSfcPath;
|
|
601
632
|
}
|
|
602
633
|
function shouldCompileVueSfcRequest(request) {
|
|
603
634
|
if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
|
|
@@ -610,6 +641,12 @@ function hasNuxtComponentQuery$1(request) {
|
|
|
610
641
|
if (!request.querySuffix) return false;
|
|
611
642
|
return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
|
|
612
643
|
}
|
|
644
|
+
function cleanVueSfcImporter(importer, request) {
|
|
645
|
+
let cleanImporter = request?.normalizedFsId ?? importer;
|
|
646
|
+
if (cleanImporter.startsWith("/@id/__x00__")) cleanImporter = cleanImporter.slice(12);
|
|
647
|
+
else if (cleanImporter.startsWith("__x00__")) cleanImporter = cleanImporter.slice(7);
|
|
648
|
+
return cleanImporter.endsWith(".vue.ts") ? cleanImporter.slice(0, -3) : cleanImporter;
|
|
649
|
+
}
|
|
613
650
|
async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, querySuffix, preserveQueryAsPath) {
|
|
614
651
|
if (path.isAbsolute(id)) return null;
|
|
615
652
|
const viteImporter = normalizeViteRequireBase(importer) ?? importer;
|
|
@@ -672,7 +709,6 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
672
709
|
return resolved;
|
|
673
710
|
}
|
|
674
711
|
if (id === "virtual:vize-styles") return RESOLVED_CSS_MODULE;
|
|
675
|
-
if (isBuild && request.normalizedFsId) return request.normalizedFsId;
|
|
676
712
|
if ((request.hasMacroQuery || request.hasDefinePageQuery) && request.isVueSfcPath) {
|
|
677
713
|
const resolved = resolveVuePath(state, request.path, importer);
|
|
678
714
|
if (resolved && fs.existsSync(resolved)) return `\0${resolved}${request.querySuffix}`;
|
|
@@ -686,12 +722,14 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
686
722
|
state.logger.log(`resolveId: skipping node_modules style import ${id}`);
|
|
687
723
|
return null;
|
|
688
724
|
}
|
|
689
|
-
return
|
|
725
|
+
return `${request.normalizedFsId ?? id}${request.styleVirtualSuffix}`;
|
|
690
726
|
}
|
|
727
|
+
if (isBuild && request.normalizedFsId) return request.normalizedFsId;
|
|
691
728
|
const isMacroImporter = importerRequest?.isMacroVirtualId ?? false;
|
|
692
729
|
const isVizeVirtualImporter = importerRequest?.isVizeVirtual ?? false;
|
|
693
|
-
|
|
694
|
-
|
|
730
|
+
const isVueSfcImporter = importerRequest?.isVueSfcPath ?? false;
|
|
731
|
+
if (importer && (isVizeVirtualImporter || isMacroImporter || isVueSfcImporter)) {
|
|
732
|
+
const cleanImporter = isMacroImporter ? importerRequest?.strippedVirtualPath ?? "" : isVizeVirtualImporter ? importerRequest?.vizeVirtualPath ?? "" : cleanVueSfcImporter(importer, importerRequest);
|
|
695
733
|
state.logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
|
|
696
734
|
if (id.startsWith("#")) try {
|
|
697
735
|
return await ctx.resolve(id, cleanImporter, { skipSelf: true });
|
|
@@ -706,6 +744,13 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
706
744
|
};
|
|
707
745
|
if (!id.startsWith("./") && !id.startsWith("../") && !id.startsWith("/")) {
|
|
708
746
|
const isVueRuntime = isVueRuntimeRequest(id);
|
|
747
|
+
if (isVueRuntime && isBuild) {
|
|
748
|
+
const vueBundlerEntry = resolveVueBundlerEntryWithNode(state, id, cleanImporter);
|
|
749
|
+
if (vueBundlerEntry) {
|
|
750
|
+
state.logger.log(`resolveId: resolved Vue runtime to ${vueBundlerEntry}`);
|
|
751
|
+
return vueBundlerEntry;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
709
754
|
const aliasRequest = resolveAliasRequest(state, id);
|
|
710
755
|
if (!isVueRuntime && aliasRequest && isViteBareSpecifier(aliasRequest)) {
|
|
711
756
|
const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter);
|
|
@@ -910,6 +955,11 @@ function hasNuxtComponentQuery(request) {
|
|
|
910
955
|
if (!request.querySuffix) return false;
|
|
911
956
|
return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
|
|
912
957
|
}
|
|
958
|
+
function normalizeStyleVirtualId(id) {
|
|
959
|
+
const withoutPrefix = id.startsWith("\0") ? id.slice(1) : id;
|
|
960
|
+
if (!withoutPrefix.includes("?vue")) return id;
|
|
961
|
+
return withoutPrefix.replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
|
|
962
|
+
}
|
|
913
963
|
function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions) {
|
|
914
964
|
const placeholderCode = getBoundaryPlaceholderCode(realPath, !!loadOptions?.ssr);
|
|
915
965
|
if (placeholderCode) {
|
|
@@ -967,18 +1017,13 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
|
|
|
967
1017
|
}
|
|
968
1018
|
function loadHook(state, id, loadOptions) {
|
|
969
1019
|
const request = classifyVitePluginRequest(id);
|
|
970
|
-
if (id !== "\0vize:all-styles.css" && !id.startsWith("\0")) {
|
|
971
|
-
if (!request.isVueSfcPath || !hasNuxtComponentQuery(request)) return null;
|
|
972
|
-
}
|
|
973
1020
|
const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
|
|
974
1021
|
if (id === "\0vize:all-styles.css") {
|
|
975
1022
|
let allCss = "";
|
|
976
1023
|
for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
|
|
977
1024
|
return allCss;
|
|
978
1025
|
}
|
|
979
|
-
|
|
980
|
-
if (id.startsWith("\0") && id.includes("?vue")) styleId = id.slice(1).replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
|
|
981
|
-
const styleRequest = classifyVitePluginRequest(styleId);
|
|
1026
|
+
const styleRequest = classifyVitePluginRequest(normalizeStyleVirtualId(id));
|
|
982
1027
|
if (styleRequest.isVueStyleQuery) {
|
|
983
1028
|
const sourceRequest = classifyVitePluginRequest(styleRequest.path);
|
|
984
1029
|
const realPath = sourceRequest.vizeVirtualPath ?? sourceRequest.normalizedFsId ?? sourceRequest.normalizedVuePath ?? styleRequest.path;
|
|
@@ -999,6 +1044,9 @@ function loadHook(state, id, loadOptions) {
|
|
|
999
1044
|
if (fallbackCompiled?.css) return resolveCssImports(fallbackCompiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase);
|
|
1000
1045
|
return "";
|
|
1001
1046
|
}
|
|
1047
|
+
if (id !== "\0vize:all-styles.css" && !id.startsWith("\0")) {
|
|
1048
|
+
if (!request.isVueSfcPath || !hasNuxtComponentQuery(request)) return null;
|
|
1049
|
+
}
|
|
1002
1050
|
if (id.startsWith("\0") && request.hasDefinePageQuery) {
|
|
1003
1051
|
const realPath = request.strippedVirtualPath ?? "";
|
|
1004
1052
|
if (request.isVueSfcPath) return loadDefinePageArtifact(state, realPath, !!loadOptions?.ssr);
|
|
@@ -1204,8 +1252,9 @@ function createVueCompatPlugin(state) {
|
|
|
1204
1252
|
};
|
|
1205
1253
|
}
|
|
1206
1254
|
function normalizeVirtualStyleId(id) {
|
|
1207
|
-
|
|
1208
|
-
|
|
1255
|
+
const withoutPrefix = id.startsWith("\0") ? id.slice(1) : id;
|
|
1256
|
+
if (!withoutPrefix.includes("?vue")) return id;
|
|
1257
|
+
return withoutPrefix.replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
|
|
1209
1258
|
}
|
|
1210
1259
|
function transformScopedPreprocessorCss(code, id) {
|
|
1211
1260
|
const request = classifyVitePluginRequest(normalizeVirtualStyleId(id));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.156.0",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@vizejs/native": "0.
|
|
42
|
+
"@vizejs/native": "0.156.0",
|
|
43
43
|
"tinyglobby": "0.2.16",
|
|
44
|
-
"vize": "0.
|
|
44
|
+
"vize": "0.156.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "25.7.0",
|