refactor: avoid assigning to bundle object

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
pull/4885/head
Alexander Lichter 4 months ago
parent ba9f50f829
commit 5c4d6c28e1

@ -334,7 +334,9 @@ export async function createVitePressPlugin(
return null return null
}, },
generateBundle(_options, bundle) { generateBundle: {
order: ssr ? null : 'post',
handler(_options, bundle) {
if (ssr) { if (ssr) {
this.emitFile({ this.emitFile({
type: 'asset', type: 'asset',
@ -352,21 +354,19 @@ export async function createVitePressPlugin(
pageToHashMap![chunk.name.toLowerCase()] = hash pageToHashMap![chunk.name.toLowerCase()] = hash
// inject another chunk with the content stripped // inject another chunk with the content stripped
bundle[name + '-lean'] = { this.emitFile({
...chunk, type: 'asset',
name: name + '-lean',
fileName: chunk.fileName.replace(/\.js$/, '.lean.js'), fileName: chunk.fileName.replace(/\.js$/, '.lean.js'),
preliminaryFileName: chunk.preliminaryFileName.replace( source: chunk.code.replace(staticStripRE, `""`)
/\.js$/, })
'.lean.js'
),
code: chunk.code.replace(staticStripRE, `""`)
}
// remove static markers from original code // remove static markers from original code
chunk.code = chunk.code.replace(staticRestoreRE, '') chunk.code = chunk.code.replace(staticRestoreRE, '')
} }
} }
} }
}
}, },
async handleHotUpdate(ctx) { async handleHotUpdate(ctx) {

Loading…
Cancel
Save