Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify manifest plugin code #18890

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading