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,36 +334,36 @@ export async function createVitePressPlugin(
return null return null
}, },
generateBundle(_options, bundle) { generateBundle: {
if (ssr) { order: ssr ? null : 'post',
this.emitFile({ handler(_options, bundle) {
type: 'asset', if (ssr) {
fileName: 'package.json', this.emitFile({
source: '{ "private": true, "type": "module" }' type: 'asset',
}) fileName: 'package.json',
} else { source: '{ "private": true, "type": "module" }'
// client build: })
// for each .md entry chunk, adjust its name to its correct path. } else {
for (const name in bundle) { // client build:
const chunk = bundle[name] // for each .md entry chunk, adjust its name to its correct path.
if (isPageChunk(chunk)) { for (const name in bundle) {
// record page -> hash relations const chunk = bundle[name]
const hash = chunk.fileName.match(hashRE)![1] if (isPageChunk(chunk)) {
pageToHashMap![chunk.name.toLowerCase()] = hash // record page -> hash relations
const hash = chunk.fileName.match(hashRE)![1]
// inject another chunk with the content stripped pageToHashMap![chunk.name.toLowerCase()] = hash
bundle[name + '-lean'] = {
...chunk, // inject another chunk with the content stripped
fileName: chunk.fileName.replace(/\.js$/, '.lean.js'), this.emitFile({
preliminaryFileName: chunk.preliminaryFileName.replace( type: 'asset',
/\.js$/, name: name + '-lean',
'.lean.js' fileName: chunk.fileName.replace(/\.js$/, '.lean.js'),
), source: chunk.code.replace(staticStripRE, `""`)
code: chunk.code.replace(staticStripRE, `""`) })
// remove static markers from original code
chunk.code = chunk.code.replace(staticRestoreRE, '')
} }
// remove static markers from original code
chunk.code = chunk.code.replace(staticRestoreRE, '')
} }
} }
} }

Loading…
Cancel
Save