mirror of
https://github.com/alex8088/electron-vite.git
synced 2025-11-10 22:43:34 +08:00
perf(bytecodePlugin): better way to count bytecode chunks
This commit is contained in:
parent
0fb8918090
commit
7587d2c674
@ -140,6 +140,8 @@ const bytecodeModuleLoaderCode = [
|
|||||||
`};`
|
`};`
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const bytecodeChunkExtensionRE = /.(jsc|cjsc)$/
|
||||||
|
|
||||||
export interface BytecodeOptions {
|
export interface BytecodeOptions {
|
||||||
chunkAlias?: string | string[]
|
chunkAlias?: string | string[]
|
||||||
transformArrowFunctions?: boolean
|
transformArrowFunctions?: boolean
|
||||||
@ -180,8 +182,6 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
return re ? { code: re.code || '', map: re.map } : null
|
return re ? { code: re.code || '', map: re.map } : null
|
||||||
}
|
}
|
||||||
|
|
||||||
let bytecodeChunkCount = 0
|
|
||||||
|
|
||||||
const useStrict = '"use strict";'
|
const useStrict = '"use strict";'
|
||||||
const bytecodeModuleLoader = 'bytecode-loader.cjs'
|
const bytecodeModuleLoader = 'bytecode-loader.cjs'
|
||||||
|
|
||||||
@ -248,6 +248,8 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`
|
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bytecodeChunkCount = 0
|
||||||
|
|
||||||
const bundles = Object.keys(output)
|
const bundles = Object.keys(output)
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@ -331,8 +333,9 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
writeBundle(): void {
|
writeBundle(_, output): void {
|
||||||
if (supported) {
|
if (supported) {
|
||||||
|
const bytecodeChunkCount = Object.keys(output).filter(chunk => bytecodeChunkExtensionRE.test(chunk)).length
|
||||||
logger.info(`${colors.green(`✓`)} ${bytecodeChunkCount} chunks compiled into bytecode.`)
|
logger.info(`${colors.green(`✓`)} ${bytecodeChunkCount} chunks compiled into bytecode.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user