Skip to content

Commit

Permalink
refactor: simplify manifest plugin code (#18890)
Browse files Browse the repository at this point in the history
  • Loading branch information
shulaoda authored Dec 6, 2024
1 parent bfbb130 commit 1bfe21b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`
)
}

Expand Down Expand Up @@ -142,8 +142,6 @@ export function manifestPlugin(): Plugin {
}
}

const fileNameToAsset = new Map<string, ManifestChunk>()

for (const file in bundle) {
const chunk = bundle[file]
if (chunk.type === 'chunk') {
Expand All @@ -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)

Expand All @@ -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)) {
Expand Down Expand Up @@ -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, '')
}
Expand Down

0 comments on commit 1bfe21b

Please sign in to comment.