mirror of https://github.com/vuejs/core.git
chore: log stats in size script
This commit is contained in:
parent
90caac473d
commit
0a16eae249
|
@ -5,6 +5,20 @@ import nodeResolve from '@rollup/plugin-node-resolve'
|
|||
import { minify } from '@swc/core'
|
||||
import replace from '@rollup/plugin-replace'
|
||||
import { brotliCompressSync, gzipSync } from 'node:zlib'
|
||||
import { parseArgs } from 'node:util'
|
||||
import pico from 'picocolors'
|
||||
import prettyBytes from 'pretty-bytes'
|
||||
|
||||
const {
|
||||
values: { write },
|
||||
} = parseArgs({
|
||||
options: {
|
||||
write: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const sizeDir = path.resolve('temp/size')
|
||||
const entry = path.resolve('./packages/vue/dist/vue.runtime.esm-bundler.js')
|
||||
|
@ -34,6 +48,7 @@ const presets: Preset[] = [
|
|||
main()
|
||||
|
||||
async function main() {
|
||||
console.log()
|
||||
const tasks: ReturnType<typeof generateBundle>[] = []
|
||||
for (const preset of presets) {
|
||||
tasks.push(generateBundle(preset))
|
||||
|
@ -46,7 +61,7 @@ async function main() {
|
|||
await mkdir(sizeDir, { recursive: true })
|
||||
await writeFile(
|
||||
path.resolve(sizeDir, '_usages.json'),
|
||||
JSON.stringify(results),
|
||||
JSON.stringify(results, null, 2),
|
||||
'utf-8',
|
||||
)
|
||||
}
|
||||
|
@ -91,6 +106,16 @@ async function generateBundle(preset: Preset) {
|
|||
const gzip = gzipSync(minified).length
|
||||
const brotli = brotliCompressSync(minified).length
|
||||
|
||||
if (write) {
|
||||
await writeFile(path.resolve(sizeDir, preset.name + '.js'), bundled)
|
||||
}
|
||||
|
||||
console.log(
|
||||
`${pico.green(pico.bold(preset.name))} - min:${prettyBytes(
|
||||
size,
|
||||
)} / gzip:${prettyBytes(gzip)} / brotli:${prettyBytes(brotli)}`,
|
||||
)
|
||||
|
||||
return {
|
||||
name: preset.name,
|
||||
size,
|
||||
|
|
Loading…
Reference in New Issue