@vizejs/vite-plugin 0.154.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 +125 -39
- 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) {
|
|
@@ -394,10 +394,17 @@ function getCompileOptionsForRequest(state, ssr) {
|
|
|
394
394
|
};
|
|
395
395
|
}
|
|
396
396
|
function syncCollectedCssForFile(state, filePath, compiled) {
|
|
397
|
-
if (!compiled || !state.
|
|
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
|
}
|
|
405
|
+
function shouldExtractCssForRequest(state, ssr) {
|
|
406
|
+
return state.isProduction && !ssr;
|
|
407
|
+
}
|
|
401
408
|
function clearBuildCaches(state) {
|
|
402
409
|
state.cache.clear();
|
|
403
410
|
state.ssrCache.clear();
|
|
@@ -430,7 +437,7 @@ async function compileAll(state) {
|
|
|
430
437
|
for (const file of deletedFiles) {
|
|
431
438
|
state.cache.delete(file);
|
|
432
439
|
state.ssrCache.delete(file);
|
|
433
|
-
state.collectedCss.delete(file);
|
|
440
|
+
if (state.extractCss) state.collectedCss.delete(file);
|
|
434
441
|
state.precompileMetadata.delete(file);
|
|
435
442
|
state.pendingHmrUpdateTypes.delete(file);
|
|
436
443
|
}
|
|
@@ -441,7 +448,7 @@ async function compileAll(state) {
|
|
|
441
448
|
return;
|
|
442
449
|
}
|
|
443
450
|
for (const file of changedFiles) {
|
|
444
|
-
state.collectedCss.delete(file);
|
|
451
|
+
if (state.extractCss) state.collectedCss.delete(file);
|
|
445
452
|
state.pendingHmrUpdateTypes.delete(file);
|
|
446
453
|
}
|
|
447
454
|
let successCount = 0;
|
|
@@ -460,7 +467,7 @@ async function compileAll(state) {
|
|
|
460
467
|
} catch (e) {
|
|
461
468
|
failedCount++;
|
|
462
469
|
state.cache.delete(file);
|
|
463
|
-
state.collectedCss.delete(file);
|
|
470
|
+
if (state.extractCss) state.collectedCss.delete(file);
|
|
464
471
|
state.precompileMetadata.delete(file);
|
|
465
472
|
precompileFailures.push(`[vize] Failed to read ${file}: ${formatUnknownError$1(e)}`);
|
|
466
473
|
state.logger.error(`Failed to read ${file}:`, e);
|
|
@@ -480,7 +487,7 @@ async function compileAll(state) {
|
|
|
480
487
|
const metadata = currentMetadata.get(fileResult.path);
|
|
481
488
|
if (fileResult.errors.length > 0) {
|
|
482
489
|
state.cache.delete(fileResult.path);
|
|
483
|
-
state.collectedCss.delete(fileResult.path);
|
|
490
|
+
if (state.extractCss) state.collectedCss.delete(fileResult.path);
|
|
484
491
|
state.precompileMetadata.delete(fileResult.path);
|
|
485
492
|
precompileFailures.push(formatCompileErrorMessage(fileResult.path, fileResult.errors));
|
|
486
493
|
continue;
|
|
@@ -509,11 +516,37 @@ const EMPTY_NATIVE_ALIAS_RULES = [];
|
|
|
509
516
|
function resolveAliasRequest(state, id) {
|
|
510
517
|
return resolveViteAliasRequest(id, nativeCssAliasRules(state));
|
|
511
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
|
+
}
|
|
512
541
|
function resolveBareImportWithNode(state, id, importer) {
|
|
513
542
|
const { request, querySuffix } = splitViteIdQuery(id);
|
|
514
|
-
for (const candidate of createViteBareImportBases(state.root, importer))
|
|
515
|
-
|
|
516
|
-
|
|
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
|
+
}
|
|
517
550
|
return null;
|
|
518
551
|
}
|
|
519
552
|
function resolveBareImportCandidatesWithNode(state, id, importer, resolvedId) {
|
|
@@ -576,9 +609,8 @@ function isVueResolvableFromRoot(root) {
|
|
|
576
609
|
const directPackageJson = path.join(rootNodeModules, "vue", "package.json");
|
|
577
610
|
cached = fs.existsSync(directPackageJson);
|
|
578
611
|
if (!cached) try {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
cached = relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
612
|
+
createRequire(path.join(root, "__vize_probe__.js")).resolve("vue/package.json");
|
|
613
|
+
cached = true;
|
|
582
614
|
} catch {}
|
|
583
615
|
vueResolvableFromRootCache.set(root, cached);
|
|
584
616
|
}
|
|
@@ -594,7 +626,9 @@ function isPotentialVizeResolveId(id) {
|
|
|
594
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");
|
|
595
627
|
}
|
|
596
628
|
function isPotentialVizeImporter(importer) {
|
|
597
|
-
|
|
629
|
+
if (importer === void 0) return false;
|
|
630
|
+
if (importer.startsWith("\0") || importer.startsWith("vize:")) return true;
|
|
631
|
+
return classifyVitePluginRequest(importer).isVueSfcPath;
|
|
598
632
|
}
|
|
599
633
|
function shouldCompileVueSfcRequest(request) {
|
|
600
634
|
if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
|
|
@@ -607,6 +641,12 @@ function hasNuxtComponentQuery$1(request) {
|
|
|
607
641
|
if (!request.querySuffix) return false;
|
|
608
642
|
return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
|
|
609
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
|
+
}
|
|
610
650
|
async function resolveAliasedVueImport(ctx, state, id, importer, isSsrRequest, handleNodeModules, querySuffix, preserveQueryAsPath) {
|
|
611
651
|
if (path.isAbsolute(id)) return null;
|
|
612
652
|
const viteImporter = normalizeViteRequireBase(importer) ?? importer;
|
|
@@ -669,7 +709,6 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
669
709
|
return resolved;
|
|
670
710
|
}
|
|
671
711
|
if (id === "virtual:vize-styles") return RESOLVED_CSS_MODULE;
|
|
672
|
-
if (isBuild && request.normalizedFsId) return request.normalizedFsId;
|
|
673
712
|
if ((request.hasMacroQuery || request.hasDefinePageQuery) && request.isVueSfcPath) {
|
|
674
713
|
const resolved = resolveVuePath(state, request.path, importer);
|
|
675
714
|
if (resolved && fs.existsSync(resolved)) return `\0${resolved}${request.querySuffix}`;
|
|
@@ -683,12 +722,14 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
683
722
|
state.logger.log(`resolveId: skipping node_modules style import ${id}`);
|
|
684
723
|
return null;
|
|
685
724
|
}
|
|
686
|
-
return
|
|
725
|
+
return `${request.normalizedFsId ?? id}${request.styleVirtualSuffix}`;
|
|
687
726
|
}
|
|
727
|
+
if (isBuild && request.normalizedFsId) return request.normalizedFsId;
|
|
688
728
|
const isMacroImporter = importerRequest?.isMacroVirtualId ?? false;
|
|
689
729
|
const isVizeVirtualImporter = importerRequest?.isVizeVirtual ?? false;
|
|
690
|
-
|
|
691
|
-
|
|
730
|
+
const isVueSfcImporter = importerRequest?.isVueSfcPath ?? false;
|
|
731
|
+
if (importer && (isVizeVirtualImporter || isMacroImporter || isVueSfcImporter)) {
|
|
732
|
+
const cleanImporter = isMacroImporter ? importerRequest?.strippedVirtualPath ?? "" : isVizeVirtualImporter ? importerRequest?.vizeVirtualPath ?? "" : cleanVueSfcImporter(importer, importerRequest);
|
|
692
733
|
state.logger.log(`resolveId from virtual: id=${id}, cleanImporter=${cleanImporter}`);
|
|
693
734
|
if (id.startsWith("#")) try {
|
|
694
735
|
return await ctx.resolve(id, cleanImporter, { skipSelf: true });
|
|
@@ -703,6 +744,13 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
703
744
|
};
|
|
704
745
|
if (!id.startsWith("./") && !id.startsWith("../") && !id.startsWith("/")) {
|
|
705
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
|
+
}
|
|
706
754
|
const aliasRequest = resolveAliasRequest(state, id);
|
|
707
755
|
if (!isVueRuntime && aliasRequest && isViteBareSpecifier(aliasRequest)) {
|
|
708
756
|
const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter);
|
|
@@ -890,19 +938,28 @@ function normalizeVueServerRendererImport(code) {
|
|
|
890
938
|
}
|
|
891
939
|
function findMacroArtifactModule(state, realPath, ssr, kind) {
|
|
892
940
|
const cache = getEnvironmentCache(state, ssr);
|
|
941
|
+
const extractCss = shouldExtractCssForRequest(state, ssr);
|
|
893
942
|
realPath = classifyVitePluginRequest(realPath).normalizedVuePath;
|
|
894
943
|
let compiled = cache.get(realPath) ?? state.cache.get(realPath) ?? state.ssrCache.get(realPath);
|
|
895
944
|
if (!compiled && fs.existsSync(realPath)) {
|
|
896
945
|
const source = fs.readFileSync(realPath, "utf-8");
|
|
897
946
|
compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, ssr), source);
|
|
898
|
-
syncCollectedCssForFile(state, realPath, compiled);
|
|
899
947
|
}
|
|
948
|
+
syncCollectedCssForFile({
|
|
949
|
+
...state,
|
|
950
|
+
extractCss
|
|
951
|
+
}, realPath, compiled);
|
|
900
952
|
return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
|
|
901
953
|
}
|
|
902
954
|
function hasNuxtComponentQuery(request) {
|
|
903
955
|
if (!request.querySuffix) return false;
|
|
904
956
|
return new URLSearchParams(request.querySuffix.slice(1)).has("nuxt_component");
|
|
905
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
|
+
}
|
|
906
963
|
function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions) {
|
|
907
964
|
const placeholderCode = getBoundaryPlaceholderCode(realPath, !!loadOptions?.ssr);
|
|
908
965
|
if (placeholderCode) {
|
|
@@ -913,12 +970,16 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
|
|
|
913
970
|
};
|
|
914
971
|
}
|
|
915
972
|
const cache = getEnvironmentCache(state, isSsr);
|
|
973
|
+
const extractCss = shouldExtractCssForRequest(state, isSsr);
|
|
916
974
|
let compiled = cache.get(realPath);
|
|
917
975
|
if (!compiled && fs.existsSync(realPath)) {
|
|
918
976
|
state.logger.log(`load: on-demand compiling ${realPath}`);
|
|
919
977
|
compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr));
|
|
920
|
-
syncCollectedCssForFile(state, realPath, compiled);
|
|
921
978
|
}
|
|
979
|
+
syncCollectedCssForFile({
|
|
980
|
+
...state,
|
|
981
|
+
extractCss
|
|
982
|
+
}, realPath, compiled);
|
|
922
983
|
if (!compiled) return null;
|
|
923
984
|
const hasDelegated = hasDelegatedStyles(compiled);
|
|
924
985
|
const pendingHmrUpdateType = loadOptions?.ssr ? void 0 : state.pendingHmrUpdateTypes.get(realPath);
|
|
@@ -931,7 +992,7 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
|
|
|
931
992
|
isDev: state.server !== null && !isSsr,
|
|
932
993
|
ssr: isSsr,
|
|
933
994
|
hmrUpdateType: pendingHmrUpdateType,
|
|
934
|
-
extractCss
|
|
995
|
+
extractCss,
|
|
935
996
|
filePath: realPath
|
|
936
997
|
});
|
|
937
998
|
const output = rewriteStaticAssetUrls(rewriteDynamicTemplateImports(isSsr ? normalizeVueServerRendererImport(generatedOutput) : generatedOutput, state.dynamicImportAliasRules), state.dynamicImportAliasRules);
|
|
@@ -956,18 +1017,13 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
|
|
|
956
1017
|
}
|
|
957
1018
|
function loadHook(state, id, loadOptions) {
|
|
958
1019
|
const request = classifyVitePluginRequest(id);
|
|
959
|
-
if (id !== "\0vize:all-styles.css" && !id.startsWith("\0")) {
|
|
960
|
-
if (!request.isVueSfcPath || !hasNuxtComponentQuery(request)) return null;
|
|
961
|
-
}
|
|
962
1020
|
const currentBase = loadOptions?.ssr ? state.serverViteBase : state.clientViteBase;
|
|
963
1021
|
if (id === "\0vize:all-styles.css") {
|
|
964
1022
|
let allCss = "";
|
|
965
1023
|
for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
|
|
966
1024
|
return allCss;
|
|
967
1025
|
}
|
|
968
|
-
|
|
969
|
-
if (id.startsWith("\0") && id.includes("?vue")) styleId = id.slice(1).replace(/\.module\.\w+$/, "").replace(/\.\w+$/, "");
|
|
970
|
-
const styleRequest = classifyVitePluginRequest(styleId);
|
|
1026
|
+
const styleRequest = classifyVitePluginRequest(normalizeStyleVirtualId(id));
|
|
971
1027
|
if (styleRequest.isVueStyleQuery) {
|
|
972
1028
|
const sourceRequest = classifyVitePluginRequest(styleRequest.path);
|
|
973
1029
|
const realPath = sourceRequest.vizeVirtualPath ?? sourceRequest.normalizedFsId ?? sourceRequest.normalizedVuePath ?? styleRequest.path;
|
|
@@ -988,6 +1044,9 @@ function loadHook(state, id, loadOptions) {
|
|
|
988
1044
|
if (fallbackCompiled?.css) return resolveCssImports(fallbackCompiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase);
|
|
989
1045
|
return "";
|
|
990
1046
|
}
|
|
1047
|
+
if (id !== "\0vize:all-styles.css" && !id.startsWith("\0")) {
|
|
1048
|
+
if (!request.isVueSfcPath || !hasNuxtComponentQuery(request)) return null;
|
|
1049
|
+
}
|
|
991
1050
|
if (id.startsWith("\0") && request.hasDefinePageQuery) {
|
|
992
1051
|
const realPath = request.strippedVirtualPath ?? "";
|
|
993
1052
|
if (request.isVueSfcPath) return loadDefinePageArtifact(state, realPath, !!loadOptions?.ssr);
|
|
@@ -1068,7 +1127,8 @@ function formatUnknownError(error) {
|
|
|
1068
1127
|
}
|
|
1069
1128
|
//#endregion
|
|
1070
1129
|
//#region src/plugin/hmr.ts
|
|
1071
|
-
const
|
|
1130
|
+
const VIZE_COMPONENTS_CSS_BASENAME = "vize-components.css";
|
|
1131
|
+
const VIZE_COMPONENTS_CSS_FILE = `assets/${VIZE_COMPONENTS_CSS_BASENAME}`;
|
|
1072
1132
|
async function handleHotUpdateHook(state, ctx) {
|
|
1073
1133
|
const { file, server, read } = ctx;
|
|
1074
1134
|
if (file.endsWith(".vue") && state.filter(file)) try {
|
|
@@ -1141,21 +1201,27 @@ function handleGenerateBundleHook(state, emitFile, bundle) {
|
|
|
1141
1201
|
let allCss = "";
|
|
1142
1202
|
for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
|
|
1143
1203
|
if (allCss.trim()) {
|
|
1204
|
+
const cssFileName = state.componentsCssFileName || VIZE_COMPONENTS_CSS_FILE;
|
|
1144
1205
|
emitFile({
|
|
1145
1206
|
type: "asset",
|
|
1146
|
-
fileName:
|
|
1207
|
+
fileName: cssFileName,
|
|
1147
1208
|
source: allCss
|
|
1148
1209
|
});
|
|
1149
|
-
attachComponentsCssToEntryChunks(bundle);
|
|
1150
|
-
state.logger.log(`Extracted CSS to ${
|
|
1210
|
+
attachComponentsCssToEntryChunks(bundle, cssFileName);
|
|
1211
|
+
state.logger.log(`Extracted CSS to ${cssFileName} (${state.collectedCss.size} components)`);
|
|
1151
1212
|
}
|
|
1152
1213
|
}
|
|
1153
|
-
function
|
|
1214
|
+
function resolveComponentsCssFileName(assetsDir) {
|
|
1215
|
+
const normalizedAssetsDir = (assetsDir || "assets").replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
1216
|
+
if (!normalizedAssetsDir || normalizedAssetsDir === ".") return VIZE_COMPONENTS_CSS_BASENAME;
|
|
1217
|
+
return `${normalizedAssetsDir}/${VIZE_COMPONENTS_CSS_BASENAME}`;
|
|
1218
|
+
}
|
|
1219
|
+
function attachComponentsCssToEntryChunks(bundle, cssFileName) {
|
|
1154
1220
|
for (const item of Object.values(bundle)) {
|
|
1155
1221
|
if (item.type !== "chunk" || !item.isEntry && !item.isDynamicEntry) continue;
|
|
1156
1222
|
item.viteMetadata ??= {};
|
|
1157
1223
|
item.viteMetadata.importedCss ??= /* @__PURE__ */ new Set();
|
|
1158
|
-
item.viteMetadata.importedCss.add(
|
|
1224
|
+
item.viteMetadata.importedCss.add(cssFileName);
|
|
1159
1225
|
}
|
|
1160
1226
|
}
|
|
1161
1227
|
//#endregion
|
|
@@ -1186,8 +1252,9 @@ function createVueCompatPlugin(state) {
|
|
|
1186
1252
|
};
|
|
1187
1253
|
}
|
|
1188
1254
|
function normalizeVirtualStyleId(id) {
|
|
1189
|
-
|
|
1190
|
-
|
|
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+$/, "");
|
|
1191
1258
|
}
|
|
1192
1259
|
function transformScopedPreprocessorCss(code, id) {
|
|
1193
1260
|
const request = classifyVitePluginRequest(normalizeVirtualStyleId(id));
|
|
@@ -1215,13 +1282,17 @@ function createPostTransformPlugin(state) {
|
|
|
1215
1282
|
state.logger.log(`post-transform: compiling virtual SFC content from ${id}`);
|
|
1216
1283
|
try {
|
|
1217
1284
|
const isSsr = !!transformOptions?.ssr;
|
|
1285
|
+
const extractCss = shouldExtractCssForRequest(state, isSsr);
|
|
1218
1286
|
const compiled = compileFile(id, getEnvironmentCache(state, isSsr), getCompileOptionsForRequest(state, isSsr), code);
|
|
1219
|
-
syncCollectedCssForFile(
|
|
1287
|
+
syncCollectedCssForFile({
|
|
1288
|
+
...state,
|
|
1289
|
+
extractCss
|
|
1290
|
+
}, id, compiled);
|
|
1220
1291
|
const result = await transformWithOxc(generateOutput(compiled, {
|
|
1221
1292
|
isProduction: state.isProduction,
|
|
1222
1293
|
isDev: state.server !== null,
|
|
1223
1294
|
ssr: isSsr,
|
|
1224
|
-
extractCss
|
|
1295
|
+
extractCss,
|
|
1225
1296
|
filePath: id
|
|
1226
1297
|
}), id, {
|
|
1227
1298
|
lang: "ts",
|
|
@@ -1374,6 +1445,13 @@ function mergeSharedConfig(baseConfig, overrideConfig) {
|
|
|
1374
1445
|
entries: [...baseConfig.entries, ...overrideConfig.entries]
|
|
1375
1446
|
};
|
|
1376
1447
|
}
|
|
1448
|
+
function shouldExtractCssForBuild(state, context) {
|
|
1449
|
+
if (!state.isProduction) return false;
|
|
1450
|
+
const environmentName = context.environment?.name;
|
|
1451
|
+
if (environmentName === "client" || environmentName === "browser") return true;
|
|
1452
|
+
if (environmentName === "ssr" || environmentName === "server") return false;
|
|
1453
|
+
return state.extractCss;
|
|
1454
|
+
}
|
|
1377
1455
|
function vize(options = {}) {
|
|
1378
1456
|
if (isLegacyVueCompatibilityMode(options)) return [createLegacyVueCompatibilityPlugin(options)];
|
|
1379
1457
|
const state = {
|
|
@@ -1396,6 +1474,7 @@ function vize(options = {}) {
|
|
|
1396
1474
|
dynamicImportAliasRules: [],
|
|
1397
1475
|
cssAliasRules: [],
|
|
1398
1476
|
extractCss: false,
|
|
1477
|
+
componentsCssFileName: "assets/vize-components.css",
|
|
1399
1478
|
clientViteDefine: {},
|
|
1400
1479
|
serverViteDefine: {},
|
|
1401
1480
|
logger: createLogger(options.debug ?? false)
|
|
@@ -1424,7 +1503,8 @@ function vize(options = {}) {
|
|
|
1424
1503
|
const currentBase = resolvedConfig.command === "serve" ? options.devUrlBase ?? resolvedConfig.base ?? "/" : resolvedConfig.base ?? "/";
|
|
1425
1504
|
if (isSsrBuild) state.serverViteBase = currentBase;
|
|
1426
1505
|
else state.clientViteBase = currentBase;
|
|
1427
|
-
state.extractCss = state.isProduction;
|
|
1506
|
+
state.extractCss = state.isProduction && !isSsrBuild;
|
|
1507
|
+
state.componentsCssFileName = resolveComponentsCssFileName(resolvedConfig.build.assetsDir);
|
|
1428
1508
|
const isSsr = !!resolvedConfig.build?.ssr;
|
|
1429
1509
|
const envDefine = {};
|
|
1430
1510
|
if (resolvedConfig.define) for (const [key, value] of Object.entries(resolvedConfig.define)) {
|
|
@@ -1508,7 +1588,10 @@ function vize(options = {}) {
|
|
|
1508
1588
|
},
|
|
1509
1589
|
async buildStart() {
|
|
1510
1590
|
if (!state.scanPatterns || state.scanPatterns.length === 0) return;
|
|
1511
|
-
await compileAll(
|
|
1591
|
+
await compileAll({
|
|
1592
|
+
...state,
|
|
1593
|
+
extractCss: shouldExtractCssForBuild(state, this)
|
|
1594
|
+
});
|
|
1512
1595
|
state.logger.log("Cache keys:", [...state.cache.keys()].slice(0, 3));
|
|
1513
1596
|
},
|
|
1514
1597
|
resolveId(id, importer, options) {
|
|
@@ -1524,7 +1607,10 @@ function vize(options = {}) {
|
|
|
1524
1607
|
return handleHotUpdateHook(state, ctx);
|
|
1525
1608
|
},
|
|
1526
1609
|
generateBundle(_, bundle) {
|
|
1527
|
-
handleGenerateBundleHook(
|
|
1610
|
+
handleGenerateBundleHook({
|
|
1611
|
+
...state,
|
|
1612
|
+
extractCss: shouldExtractCssForBuild(state, this)
|
|
1613
|
+
}, this.emitFile.bind(this), bundle);
|
|
1528
1614
|
},
|
|
1529
1615
|
closeBundle() {
|
|
1530
1616
|
if (state.server === null) clearBuildCaches(state);
|
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",
|