From 7587d2c674f21e424ab641f2dd72b8e4a576c978 Mon Sep 17 00:00:00 2001 From: alex8088 <244096523@qq.com> Date: Sun, 19 Oct 2025 14:49:09 +0800 Subject: [PATCH] perf(bytecodePlugin): better way to count bytecode chunks --- src/plugins/bytecode.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/bytecode.ts b/src/plugins/bytecode.ts index eeed31c..9b49adc 100644 --- a/src/plugins/bytecode.ts +++ b/src/plugins/bytecode.ts @@ -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.`) } }