@@ -5,6 +5,20 @@ import nodeResolve from '@rollup/plugin-node-resolve'
5
5
import { minify } from '@swc/core'
6
6
import replace from '@rollup/plugin-replace'
7
7
import { brotliCompressSync , gzipSync } from 'node:zlib'
8
+ import { parseArgs } from 'node:util'
9
+ import pico from 'picocolors'
10
+ import prettyBytes from 'pretty-bytes'
11
+
12
+ const {
13
+ values : { write } ,
14
+ } = parseArgs ( {
15
+ options : {
16
+ write : {
17
+ type : 'boolean' ,
18
+ default : false ,
19
+ } ,
20
+ } ,
21
+ } )
8
22
9
23
const sizeDir = path . resolve ( 'temp/size' )
10
24
const entry = path . resolve ( './packages/vue/dist/vue.runtime.esm-bundler.js' )
@@ -34,6 +48,7 @@ const presets: Preset[] = [
34
48
main ( )
35
49
36
50
async function main ( ) {
51
+ console . log ( )
37
52
const tasks : ReturnType < typeof generateBundle > [ ] = [ ]
38
53
for ( const preset of presets ) {
39
54
tasks . push ( generateBundle ( preset ) )
@@ -46,7 +61,7 @@ async function main() {
46
61
await mkdir ( sizeDir , { recursive : true } )
47
62
await writeFile (
48
63
path . resolve ( sizeDir , '_usages.json' ) ,
49
- JSON . stringify ( results ) ,
64
+ JSON . stringify ( results , null , 2 ) ,
50
65
'utf-8' ,
51
66
)
52
67
}
@@ -91,6 +106,16 @@ async function generateBundle(preset: Preset) {
91
106
const gzip = gzipSync ( minified ) . length
92
107
const brotli = brotliCompressSync ( minified ) . length
93
108
109
+ if ( write ) {
110
+ await writeFile ( path . resolve ( sizeDir , preset . name + '.js' ) , bundled )
111
+ }
112
+
113
+ console . log (
114
+ `${ pico . green ( pico . bold ( preset . name ) ) } - min:${ prettyBytes (
115
+ size ,
116
+ ) } / gzip:${ prettyBytes ( gzip ) } / brotli:${ prettyBytes ( brotli ) } `,
117
+ )
118
+
94
119
return {
95
120
name : preset . name ,
96
121
size,
0 commit comments