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) }