@@ -84,20 +84,27 @@ const {
8484} = values
8585
8686const formats = rawFormats ?. split ( ',' )
87+ const sizeDir = path . resolve ( __dirname , '../temp/size' )
8788
8889async function main ( ) {
8990 await run ( )
9091
9192 async function run ( ) {
93+ if ( size ) {
94+ await fs . mkdir ( sizeDir , { recursive : true } )
95+ }
96+
9297 const rtsCachePath = path . resolve ( __dirname , './node_modules/.rts2_cache' )
9398 if ( isRelease && existsSync ( rtsCachePath ) ) {
9499 // remove build cache for release builds to avoid outdated enum values
95100 await fs . rm ( rtsCachePath , { recursive : true } )
96101 }
102+
97103 const resolvedTargets = targets . length
98104 ? await fuzzyMatchTarget ( targets , buildAllMatching )
99105 : await allTargets ( )
100106 await buildAll ( resolvedTargets )
107+
101108 if ( size ) {
102109 await checkAllSizes ( resolvedTargets )
103110 }
@@ -273,6 +280,8 @@ async function main() {
273280 return
274281 }
275282 const file = await fs . readFile ( filePath )
283+ const filename = path . basename ( filePath )
284+
276285 const minSize = ( file . length / 1024 ) . toFixed ( 2 ) + 'kb'
277286 const gzipped = gzipSync ( file )
278287 const gzippedSize = ( gzipped . length / 1024 ) . toFixed ( 2 ) + 'kb'
@@ -284,6 +293,24 @@ async function main() {
284293 pc . bold ( path . basename ( filePath ) )
285294 ) } min:${ minSize } / gzip:${ gzippedSize } / brotli:${ compressedSize } `
286295 )
296+
297+ if ( size ) {
298+ const sizeContents = JSON . stringify (
299+ {
300+ file : filename ,
301+ size : file . length ,
302+ gzip : gzipped . length ,
303+ brotli : compressed . length
304+ } ,
305+ null ,
306+ 2
307+ )
308+ await fs . writeFile (
309+ path . resolve ( sizeDir , `${ filename } .json` ) ,
310+ sizeContents ,
311+ 'utf-8'
312+ )
313+ }
287314 }
288315}
289316
0 commit comments