From 1bfe21b9440f318c940f90e425a18588595225fd Mon Sep 17 00:00:00 2001 From: dalaoshu Date: Fri, 6 Dec 2024 17:53:48 +0800 Subject: [PATCH] refactor: simplify manifest plugin code (#18890) --- packages/vite/src/node/plugins/manifest.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/manifest.ts b/packages/vite/src/node/plugins/manifest.ts index c46ac8a61ce2f3..ea58d16a21903f 100644 --- a/packages/vite/src/node/plugins/manifest.ts +++ b/packages/vite/src/node/plugins/manifest.ts @@ -59,7 +59,7 @@ export function manifestPlugin(): Plugin { function getChunkName(chunk: OutputChunk) { return ( getChunkOriginalFileName(chunk, root, format) ?? - `_` + path.basename(chunk.fileName) + `_${path.basename(chunk.fileName)}` ) } @@ -142,8 +142,6 @@ export function manifestPlugin(): Plugin { } } - const fileNameToAsset = new Map() - for (const file in bundle) { const chunk = bundle[file] if (chunk.type === 'chunk') { @@ -153,7 +151,7 @@ export function manifestPlugin(): Plugin { const src = chunk.originalFileNames.length > 0 ? chunk.originalFileNames[0] - : '_' + path.basename(chunk.fileName) + : `_${path.basename(chunk.fileName)}` const isEntry = entryCssAssetFileNames.has(chunk.fileName) const asset = createAsset(chunk, src, isEntry) @@ -162,7 +160,6 @@ export function manifestPlugin(): Plugin { const file = manifest[src]?.file if (!(file && endsWithJSRE.test(file))) { manifest[src] = asset - fileNameToAsset.set(chunk.fileName, asset) } for (const originalFileName of chunk.originalFileNames.slice(1)) { @@ -201,7 +198,7 @@ export function getChunkOriginalFileName( if (format === 'system' && !chunk.name.includes('-legacy')) { const ext = path.extname(name) const endPos = ext.length !== 0 ? -ext.length : undefined - name = name.slice(0, endPos) + `-legacy` + ext + name = `${name.slice(0, endPos)}-legacy${ext}` } return name.replace(/\0/g, '') }