From 2f09b9c333f1a4ca847d90d37752a749fad43ed9 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:03:47 +0900 Subject: [PATCH] fix: use preliminaryFileName for chunkMetadata key --- packages/vite/src/node/plugins/metadata.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/metadata.ts b/packages/vite/src/node/plugins/metadata.ts index 3b9469dbd27ab6..12147461158bf4 100644 --- a/packages/vite/src/node/plugins/metadata.ts +++ b/packages/vite/src/node/plugins/metadata.ts @@ -15,7 +15,7 @@ export function metadataPlugin(): Plugin { async renderChunk(_code, chunk) { // Since the chunk come from rust side, mutate it directly will not sync back to rust side. // The next usage will lost the metadata - chunkMetadataMap.set(chunk.name, { + chunkMetadataMap.set(chunk.fileName, { importedAssets: new Set(), importedCss: new Set(), }) @@ -28,6 +28,7 @@ export function metadataPlugin(): Plugin { export function getChunkMetadata( chunk: RenderedChunk | OutputChunk, ): ChunkMetadata | undefined { - // TODO: chunk.name is not unique, use something unique like chunk.preliminaryFileName / chunk.fileName - return chunkMetadataMap.get(chunk.name) + const preliminaryFileName = + 'preliminaryFileName' in chunk ? chunk.preliminaryFileName : chunk.fileName + return chunkMetadataMap.get(preliminaryFileName) }