perf(bytecodePlugin): better way to count bytecode chunks

This commit is contained in:
alex8088 2025-10-19 14:49:09 +08:00
parent 0fb8918090
commit 7587d2c674

View File

@ -140,6 +140,8 @@ const bytecodeModuleLoaderCode = [
`};`
]
const bytecodeChunkExtensionRE = /.(jsc|cjsc)$/
export interface BytecodeOptions {
chunkAlias?: string | string[]
transformArrowFunctions?: boolean
@ -180,8 +182,6 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
return re ? { code: re.code || '', map: re.map } : null
}
let bytecodeChunkCount = 0
const useStrict = '"use strict";'
const bytecodeModuleLoader = 'bytecode-loader.cjs'
@ -248,6 +248,8 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`
}
let bytecodeChunkCount = 0
const bundles = Object.keys(output)
await Promise.all(
@ -331,8 +333,9 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
})
}
},
writeBundle(): void {
writeBundle(_, output): void {
if (supported) {
const bytecodeChunkCount = Object.keys(output).filter(chunk => bytecodeChunkExtensionRE.test(chunk)).length
logger.info(`${colors.green(``)} ${bytecodeChunkCount} chunks compiled into bytecode.`)
}
}