From c148676c90dc4823bc6bdeb8ba1e36386c5d9654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 25 Oct 2024 20:16:30 +0900 Subject: [PATCH] fix(manifest): non entry CSS chunk src was wrong (#18133) --- docs/guide/backend-integration.md | 8 ++++---- packages/vite/src/node/plugins/manifest.ts | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/guide/backend-integration.md b/docs/guide/backend-integration.md index 1bf6265f8..5a6cb5ce7 100644 --- a/docs/guide/backend-integration.md +++ b/docs/guide/backend-integration.md @@ -61,15 +61,15 @@ If you need a custom integration, you can follow the steps in this guide to conf ```json [.vite/manifest.json] { - "_shared-!~{003}~.js": { - "file": "assets/shared-ChJ_j-JJ.css", - "src": "_shared-!~{003}~.js" - }, "_shared-B7PI925R.js": { "file": "assets/shared-B7PI925R.js", "name": "shared", "css": ["assets/shared-ChJ_j-JJ.css"] }, + "_shared-ChJ_j-JJ.css": { + "file": "assets/shared-ChJ_j-JJ.css", + "src": "_shared-ChJ_j-JJ.css" + }, "baz.js": { "file": "assets/baz-B2H3sXNv.js", "name": "baz", diff --git a/packages/vite/src/node/plugins/manifest.ts b/packages/vite/src/node/plugins/manifest.ts index 69538f370..c4c449931 100644 --- a/packages/vite/src/node/plugins/manifest.ts +++ b/packages/vite/src/node/plugins/manifest.ts @@ -57,7 +57,10 @@ export function manifestPlugin(): Plugin { const buildOptions = this.environment.config.build function getChunkName(chunk: OutputChunk) { - return getChunkOriginalFileName(chunk, root, format) + return ( + getChunkOriginalFileName(chunk, root, format) ?? + `_` + path.basename(chunk.fileName) + ) } function getInternalImports(imports: string[]): string[] { @@ -150,7 +153,7 @@ export function manifestPlugin(): Plugin { const src = chunk.originalFileNames.length > 0 ? chunk.originalFileNames[0] - : chunk.names[0] + : '_' + path.basename(chunk.fileName) const isEntry = entryCssAssetFileNames.has(chunk.fileName) const asset = createAsset(chunk, src, isEntry) @@ -189,7 +192,7 @@ export function getChunkOriginalFileName( chunk: OutputChunk | RenderedChunk, root: string, format: InternalModuleFormat, -): string { +): string | undefined { if (chunk.facadeModuleId) { let name = normalizePath(path.relative(root, chunk.facadeModuleId)) if (format === 'system' && !chunk.name.includes('-legacy')) { @@ -198,7 +201,5 @@ export function getChunkOriginalFileName( name = name.slice(0, endPos) + `-legacy` + ext } return name.replace(/\0/g, '') - } else { - return `_` + path.basename(chunk.fileName) } }