@vizejs/vite-plugin 0.154.0 → 0.155.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 +56 -19
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -394,10 +394,13 @@ 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
398
|
if (compiled.css && !hasDelegatedStyles(compiled)) state.collectedCss.set(filePath, resolveCssImports(compiled.css, filePath, state.cssAliasRules, false));
|
|
399
399
|
else state.collectedCss.delete(filePath);
|
|
400
400
|
}
|
|
401
|
+
function shouldExtractCssForRequest(state, ssr) {
|
|
402
|
+
return state.isProduction && !ssr;
|
|
403
|
+
}
|
|
401
404
|
function clearBuildCaches(state) {
|
|
402
405
|
state.cache.clear();
|
|
403
406
|
state.ssrCache.clear();
|
|
@@ -430,7 +433,7 @@ async function compileAll(state) {
|
|
|
430
433
|
for (const file of deletedFiles) {
|
|
431
434
|
state.cache.delete(file);
|
|
432
435
|
state.ssrCache.delete(file);
|
|
433
|
-
state.collectedCss.delete(file);
|
|
436
|
+
if (state.extractCss) state.collectedCss.delete(file);
|
|
434
437
|
state.precompileMetadata.delete(file);
|
|
435
438
|
state.pendingHmrUpdateTypes.delete(file);
|
|
436
439
|
}
|
|
@@ -441,7 +444,7 @@ async function compileAll(state) {
|
|
|
441
444
|
return;
|
|
442
445
|
}
|
|
443
446
|
for (const file of changedFiles) {
|
|
444
|
-
state.collectedCss.delete(file);
|
|
447
|
+
if (state.extractCss) state.collectedCss.delete(file);
|
|
445
448
|
state.pendingHmrUpdateTypes.delete(file);
|
|
446
449
|
}
|
|
447
450
|
let successCount = 0;
|
|
@@ -460,7 +463,7 @@ async function compileAll(state) {
|
|
|
460
463
|
} catch (e) {
|
|
461
464
|
failedCount++;
|
|
462
465
|
state.cache.delete(file);
|
|
463
|
-
state.collectedCss.delete(file);
|
|
466
|
+
if (state.extractCss) state.collectedCss.delete(file);
|
|
464
467
|
state.precompileMetadata.delete(file);
|
|
465
468
|
precompileFailures.push(`[vize] Failed to read ${file}: ${formatUnknownError$1(e)}`);
|
|
466
469
|
state.logger.error(`Failed to read ${file}:`, e);
|
|
@@ -480,7 +483,7 @@ async function compileAll(state) {
|
|
|
480
483
|
const metadata = currentMetadata.get(fileResult.path);
|
|
481
484
|
if (fileResult.errors.length > 0) {
|
|
482
485
|
state.cache.delete(fileResult.path);
|
|
483
|
-
state.collectedCss.delete(fileResult.path);
|
|
486
|
+
if (state.extractCss) state.collectedCss.delete(fileResult.path);
|
|
484
487
|
state.precompileMetadata.delete(fileResult.path);
|
|
485
488
|
precompileFailures.push(formatCompileErrorMessage(fileResult.path, fileResult.errors));
|
|
486
489
|
continue;
|
|
@@ -890,13 +893,17 @@ function normalizeVueServerRendererImport(code) {
|
|
|
890
893
|
}
|
|
891
894
|
function findMacroArtifactModule(state, realPath, ssr, kind) {
|
|
892
895
|
const cache = getEnvironmentCache(state, ssr);
|
|
896
|
+
const extractCss = shouldExtractCssForRequest(state, ssr);
|
|
893
897
|
realPath = classifyVitePluginRequest(realPath).normalizedVuePath;
|
|
894
898
|
let compiled = cache.get(realPath) ?? state.cache.get(realPath) ?? state.ssrCache.get(realPath);
|
|
895
899
|
if (!compiled && fs.existsSync(realPath)) {
|
|
896
900
|
const source = fs.readFileSync(realPath, "utf-8");
|
|
897
901
|
compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, ssr), source);
|
|
898
|
-
syncCollectedCssForFile(state, realPath, compiled);
|
|
899
902
|
}
|
|
903
|
+
syncCollectedCssForFile({
|
|
904
|
+
...state,
|
|
905
|
+
extractCss
|
|
906
|
+
}, realPath, compiled);
|
|
900
907
|
return compiled?.macroArtifacts?.find((artifact) => artifact.kind === kind)?.moduleCode ?? null;
|
|
901
908
|
}
|
|
902
909
|
function hasNuxtComponentQuery(request) {
|
|
@@ -913,12 +920,16 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
|
|
|
913
920
|
};
|
|
914
921
|
}
|
|
915
922
|
const cache = getEnvironmentCache(state, isSsr);
|
|
923
|
+
const extractCss = shouldExtractCssForRequest(state, isSsr);
|
|
916
924
|
let compiled = cache.get(realPath);
|
|
917
925
|
if (!compiled && fs.existsSync(realPath)) {
|
|
918
926
|
state.logger.log(`load: on-demand compiling ${realPath}`);
|
|
919
927
|
compiled = compileFile(realPath, cache, getCompileOptionsForRequest(state, isSsr));
|
|
920
|
-
syncCollectedCssForFile(state, realPath, compiled);
|
|
921
928
|
}
|
|
929
|
+
syncCollectedCssForFile({
|
|
930
|
+
...state,
|
|
931
|
+
extractCss
|
|
932
|
+
}, realPath, compiled);
|
|
922
933
|
if (!compiled) return null;
|
|
923
934
|
const hasDelegated = hasDelegatedStyles(compiled);
|
|
924
935
|
const pendingHmrUpdateType = loadOptions?.ssr ? void 0 : state.pendingHmrUpdateTypes.get(realPath);
|
|
@@ -931,7 +942,7 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
|
|
|
931
942
|
isDev: state.server !== null && !isSsr,
|
|
932
943
|
ssr: isSsr,
|
|
933
944
|
hmrUpdateType: pendingHmrUpdateType,
|
|
934
|
-
extractCss
|
|
945
|
+
extractCss,
|
|
935
946
|
filePath: realPath
|
|
936
947
|
});
|
|
937
948
|
const output = rewriteStaticAssetUrls(rewriteDynamicTemplateImports(isSsr ? normalizeVueServerRendererImport(generatedOutput) : generatedOutput, state.dynamicImportAliasRules), state.dynamicImportAliasRules);
|
|
@@ -1068,7 +1079,8 @@ function formatUnknownError(error) {
|
|
|
1068
1079
|
}
|
|
1069
1080
|
//#endregion
|
|
1070
1081
|
//#region src/plugin/hmr.ts
|
|
1071
|
-
const
|
|
1082
|
+
const VIZE_COMPONENTS_CSS_BASENAME = "vize-components.css";
|
|
1083
|
+
const VIZE_COMPONENTS_CSS_FILE = `assets/${VIZE_COMPONENTS_CSS_BASENAME}`;
|
|
1072
1084
|
async function handleHotUpdateHook(state, ctx) {
|
|
1073
1085
|
const { file, server, read } = ctx;
|
|
1074
1086
|
if (file.endsWith(".vue") && state.filter(file)) try {
|
|
@@ -1141,21 +1153,27 @@ function handleGenerateBundleHook(state, emitFile, bundle) {
|
|
|
1141
1153
|
let allCss = "";
|
|
1142
1154
|
for (const css of state.collectedCss.values()) allCss += allCss ? `\n\n${css}` : css;
|
|
1143
1155
|
if (allCss.trim()) {
|
|
1156
|
+
const cssFileName = state.componentsCssFileName || VIZE_COMPONENTS_CSS_FILE;
|
|
1144
1157
|
emitFile({
|
|
1145
1158
|
type: "asset",
|
|
1146
|
-
fileName:
|
|
1159
|
+
fileName: cssFileName,
|
|
1147
1160
|
source: allCss
|
|
1148
1161
|
});
|
|
1149
|
-
attachComponentsCssToEntryChunks(bundle);
|
|
1150
|
-
state.logger.log(`Extracted CSS to ${
|
|
1162
|
+
attachComponentsCssToEntryChunks(bundle, cssFileName);
|
|
1163
|
+
state.logger.log(`Extracted CSS to ${cssFileName} (${state.collectedCss.size} components)`);
|
|
1151
1164
|
}
|
|
1152
1165
|
}
|
|
1153
|
-
function
|
|
1166
|
+
function resolveComponentsCssFileName(assetsDir) {
|
|
1167
|
+
const normalizedAssetsDir = (assetsDir || "assets").replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
1168
|
+
if (!normalizedAssetsDir || normalizedAssetsDir === ".") return VIZE_COMPONENTS_CSS_BASENAME;
|
|
1169
|
+
return `${normalizedAssetsDir}/${VIZE_COMPONENTS_CSS_BASENAME}`;
|
|
1170
|
+
}
|
|
1171
|
+
function attachComponentsCssToEntryChunks(bundle, cssFileName) {
|
|
1154
1172
|
for (const item of Object.values(bundle)) {
|
|
1155
1173
|
if (item.type !== "chunk" || !item.isEntry && !item.isDynamicEntry) continue;
|
|
1156
1174
|
item.viteMetadata ??= {};
|
|
1157
1175
|
item.viteMetadata.importedCss ??= /* @__PURE__ */ new Set();
|
|
1158
|
-
item.viteMetadata.importedCss.add(
|
|
1176
|
+
item.viteMetadata.importedCss.add(cssFileName);
|
|
1159
1177
|
}
|
|
1160
1178
|
}
|
|
1161
1179
|
//#endregion
|
|
@@ -1215,13 +1233,17 @@ function createPostTransformPlugin(state) {
|
|
|
1215
1233
|
state.logger.log(`post-transform: compiling virtual SFC content from ${id}`);
|
|
1216
1234
|
try {
|
|
1217
1235
|
const isSsr = !!transformOptions?.ssr;
|
|
1236
|
+
const extractCss = shouldExtractCssForRequest(state, isSsr);
|
|
1218
1237
|
const compiled = compileFile(id, getEnvironmentCache(state, isSsr), getCompileOptionsForRequest(state, isSsr), code);
|
|
1219
|
-
syncCollectedCssForFile(
|
|
1238
|
+
syncCollectedCssForFile({
|
|
1239
|
+
...state,
|
|
1240
|
+
extractCss
|
|
1241
|
+
}, id, compiled);
|
|
1220
1242
|
const result = await transformWithOxc(generateOutput(compiled, {
|
|
1221
1243
|
isProduction: state.isProduction,
|
|
1222
1244
|
isDev: state.server !== null,
|
|
1223
1245
|
ssr: isSsr,
|
|
1224
|
-
extractCss
|
|
1246
|
+
extractCss,
|
|
1225
1247
|
filePath: id
|
|
1226
1248
|
}), id, {
|
|
1227
1249
|
lang: "ts",
|
|
@@ -1374,6 +1396,13 @@ function mergeSharedConfig(baseConfig, overrideConfig) {
|
|
|
1374
1396
|
entries: [...baseConfig.entries, ...overrideConfig.entries]
|
|
1375
1397
|
};
|
|
1376
1398
|
}
|
|
1399
|
+
function shouldExtractCssForBuild(state, context) {
|
|
1400
|
+
if (!state.isProduction) return false;
|
|
1401
|
+
const environmentName = context.environment?.name;
|
|
1402
|
+
if (environmentName === "client" || environmentName === "browser") return true;
|
|
1403
|
+
if (environmentName === "ssr" || environmentName === "server") return false;
|
|
1404
|
+
return state.extractCss;
|
|
1405
|
+
}
|
|
1377
1406
|
function vize(options = {}) {
|
|
1378
1407
|
if (isLegacyVueCompatibilityMode(options)) return [createLegacyVueCompatibilityPlugin(options)];
|
|
1379
1408
|
const state = {
|
|
@@ -1396,6 +1425,7 @@ function vize(options = {}) {
|
|
|
1396
1425
|
dynamicImportAliasRules: [],
|
|
1397
1426
|
cssAliasRules: [],
|
|
1398
1427
|
extractCss: false,
|
|
1428
|
+
componentsCssFileName: "assets/vize-components.css",
|
|
1399
1429
|
clientViteDefine: {},
|
|
1400
1430
|
serverViteDefine: {},
|
|
1401
1431
|
logger: createLogger(options.debug ?? false)
|
|
@@ -1424,7 +1454,8 @@ function vize(options = {}) {
|
|
|
1424
1454
|
const currentBase = resolvedConfig.command === "serve" ? options.devUrlBase ?? resolvedConfig.base ?? "/" : resolvedConfig.base ?? "/";
|
|
1425
1455
|
if (isSsrBuild) state.serverViteBase = currentBase;
|
|
1426
1456
|
else state.clientViteBase = currentBase;
|
|
1427
|
-
state.extractCss = state.isProduction;
|
|
1457
|
+
state.extractCss = state.isProduction && !isSsrBuild;
|
|
1458
|
+
state.componentsCssFileName = resolveComponentsCssFileName(resolvedConfig.build.assetsDir);
|
|
1428
1459
|
const isSsr = !!resolvedConfig.build?.ssr;
|
|
1429
1460
|
const envDefine = {};
|
|
1430
1461
|
if (resolvedConfig.define) for (const [key, value] of Object.entries(resolvedConfig.define)) {
|
|
@@ -1508,7 +1539,10 @@ function vize(options = {}) {
|
|
|
1508
1539
|
},
|
|
1509
1540
|
async buildStart() {
|
|
1510
1541
|
if (!state.scanPatterns || state.scanPatterns.length === 0) return;
|
|
1511
|
-
await compileAll(
|
|
1542
|
+
await compileAll({
|
|
1543
|
+
...state,
|
|
1544
|
+
extractCss: shouldExtractCssForBuild(state, this)
|
|
1545
|
+
});
|
|
1512
1546
|
state.logger.log("Cache keys:", [...state.cache.keys()].slice(0, 3));
|
|
1513
1547
|
},
|
|
1514
1548
|
resolveId(id, importer, options) {
|
|
@@ -1524,7 +1558,10 @@ function vize(options = {}) {
|
|
|
1524
1558
|
return handleHotUpdateHook(state, ctx);
|
|
1525
1559
|
},
|
|
1526
1560
|
generateBundle(_, bundle) {
|
|
1527
|
-
handleGenerateBundleHook(
|
|
1561
|
+
handleGenerateBundleHook({
|
|
1562
|
+
...state,
|
|
1563
|
+
extractCss: shouldExtractCssForBuild(state, this)
|
|
1564
|
+
}, this.emitFile.bind(this), bundle);
|
|
1528
1565
|
},
|
|
1529
1566
|
closeBundle() {
|
|
1530
1567
|
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.155.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.155.0",
|
|
43
43
|
"tinyglobby": "0.2.16",
|
|
44
|
-
"vize": "0.
|
|
44
|
+
"vize": "0.155.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "25.7.0",
|