11import terser from "@rollup/plugin-terser" ;
22import { readFile } from "node:fs/promises" ;
33import { dirname , isAbsolute , join , relative , resolve } from "node:path" ;
4+ import { brotliCompressSync , gzipSync } from "node:zlib" ;
45import { rollup } from "rollup" ;
56import { dts } from "rollup-plugin-dts" ;
67import { bundleName , dist , moduleNames , root , tscOut } from "./common.js" ;
@@ -75,7 +76,7 @@ for (const moduleName of moduleNames) {
7576 ] ,
7677 } ) ;
7778
78- await esBundle . write ( {
79+ logOutputStats ( await esBundle . write ( {
7980 format : "es" ,
8081 file : join ( dist , bundleName ( moduleName ) + ".js" ) ,
8182 paths : id => {
@@ -87,9 +88,9 @@ for (const moduleName of moduleNames) {
8788 bannerPlugin ,
8889 formatPlugin ,
8990 ] ,
90- } ) ;
91+ } ) ) ;
9192
92- await esBundle . write ( {
93+ logOutputStats ( await esBundle . write ( {
9394 format : "es" ,
9495 file : join ( dist , bundleName ( moduleName ) + ".min.js" ) ,
9596 paths : id => {
@@ -100,7 +101,7 @@ for (const moduleName of moduleNames) {
100101 plugins : [
101102 terser ( ) ,
102103 ] ,
103- } ) ;
104+ } ) ) ;
104105
105106 const typesBundle = await rollup ( {
106107 logLevel : "silent" ,
@@ -131,3 +132,18 @@ for (const moduleName of moduleNames) {
131132
132133 console . groupEnd ( ) ;
133134}
135+
136+ function logOutputStats ( { output } ) {
137+ function kb ( bytes ) {
138+ return ( bytes / 1000 ) . toFixed ( 1 ) + "kb" ;
139+ }
140+
141+ for ( const entry of output ) {
142+ console . group ( `${ entry . fileName } : ${ kb ( entry . code . length ) } ` ) ;
143+ if ( entry . fileName . endsWith ( ".min.js" ) ) {
144+ console . log ( " gzip:" , kb ( gzipSync ( entry . code ) . length ) ) ;
145+ console . log ( "brotli:" , kb ( brotliCompressSync ( entry . code ) . length ) ) ;
146+ }
147+ console . groupEnd ( ) ;
148+ }
149+ }
0 commit comments