@@ -6,19 +6,21 @@ import gzip from "gzip-size";
66import brotli from "brotli-size" ;
77import terser from "terser" ;
88
9- function render ( opt , outputOptions , sizes ) {
9+ function render ( opt , outputOptions , info ) {
1010 const primaryColor = opt . theme === "dark" ? "green" : "black" ;
1111 const secondaryColor = opt . theme === "dark" ? "yellow" : "blue" ;
1212
1313 const title = colors [ primaryColor ] . bold ;
1414 const value = colors [ secondaryColor ] ;
1515
1616 const values = [
17- ...( outputOptions . file ? [ `${ title ( "Destination: " ) } ${ value ( outputOptions . file ) } ` ] : [ ] ) ,
18- ...[ `${ title ( "Bundle Size: " ) } ${ value ( sizes . bundleSize ) } ` ] ,
19- ...( sizes . minSize ? [ `${ title ( "Minified Size: " ) } ${ value ( sizes . minSize ) } ` ] : [ ] ) ,
20- ...( sizes . gzipSize ? [ `${ title ( "Gzipped Size: " ) } ${ value ( sizes . gzipSize ) } ` ] : [ ] ) ,
21- ...( sizes . brotliSize ? [ `${ title ( "Brotli size: " ) } ${ value ( sizes . brotliSize ) } ` ] : [ ] )
17+ ...( outputOptions . file ?
18+ [ `${ title ( "Destination: " ) } ${ value ( outputOptions . file ) } ` ] :
19+ ( info . fileName ? [ `${ title ( "Bundle Name: " ) } ${ value ( info . fileName ) } ` ] : [ ] ) ) ,
20+ ...[ `${ title ( "Bundle Size: " ) } ${ value ( info . bundleSize ) } ` ] ,
21+ ...( info . minSize ? [ `${ title ( "Minified Size: " ) } ${ value ( info . minSize ) } ` ] : [ ] ) ,
22+ ...( info . gzipSize ? [ `${ title ( "Gzipped Size: " ) } ${ value ( info . gzipSize ) } ` ] : [ ] ) ,
23+ ...( info . brotliSize ? [ `${ title ( "Brotli size: " ) } ${ value ( info . brotliSize ) } ` ] : [ ] )
2224 ] ;
2325
2426 return boxen ( values . join ( "\n" ) , { padding : 1 } ) ;
@@ -39,25 +41,29 @@ export default function filesize(options = {}, env) {
3941 opts . render = options . render ;
4042 }
4143
42- const getData = function ( outputOptions , code ) {
43- const sizes = { } ;
44- sizes . bundleSize = fileSize ( Buffer . byteLength ( code ) , opts . format ) ;
44+ const getData = function ( outputOptions , bundle ) {
45+ const { code , fileName } = bundle ;
46+ const info = { } ;
4547
46- sizes . brotliSize = opts . showBrotliSize
48+ info . fileName = fileName ;
49+
50+ info . bundleSize = fileSize ( Buffer . byteLength ( code ) , opts . format ) ;
51+
52+ info . brotliSize = opts . showBrotliSize
4753 ? fileSize ( brotli . sync ( code ) , opts . format )
4854 : "" ;
4955
5056 if ( opts . showMinifiedSize || opts . showGzippedSize ) {
5157 const minifiedCode = terser . minify ( code ) . code ;
52- sizes . minSize = opts . showMinifiedSize
58+ info . minSize = opts . showMinifiedSize
5359 ? fileSize ( minifiedCode . length , opts . format )
5460 : "" ;
55- sizes . gzipSize = opts . showGzippedSize
61+ info . gzipSize = opts . showGzippedSize
5662 ? fileSize ( gzip . sync ( minifiedCode ) , opts . format )
5763 : "" ;
5864 }
5965
60- return opts . render ( opts , outputOptions , sizes ) ;
66+ return opts . render ( opts , outputOptions , info ) ;
6167 } ;
6268
6369 if ( env === "test" ) {
@@ -71,7 +77,7 @@ export default function filesize(options = {}, env) {
7177 . map ( fileName => bundle [ fileName ] )
7278 . filter ( currentBundle => ! currentBundle . isAsset )
7379 . forEach ( ( currentBundle ) => {
74- console . log ( getData ( outputOptions , currentBundle . code ) )
80+ console . log ( getData ( outputOptions , currentBundle ) )
7581 } ) ;
7682 }
7783 } ;
0 commit comments