@@ -11,6 +11,7 @@ const Logger = require('../Logger');
1111const utils = require ( '../utils' ) ;
1212
1313const SIZES = new Set ( [ 'stat' , 'parsed' , 'gzip' ] ) ;
14+ const COMPRESSION_ALGORITHMS = new Set ( [ 'gzip' , 'brotli' ] ) ;
1415
1516const program = commander
1617 . version ( require ( '../../package.json' ) . version )
@@ -58,6 +59,12 @@ const program = commander
5859 br ( `Possible values: ${ [ ...SIZES ] . join ( ', ' ) } ` ) ,
5960 'parsed'
6061 )
62+ . option (
63+ '--compression-algorithm <type>' ,
64+ 'Compression algorithm that will be used to calculate the compressed module sizes.' +
65+ br ( `Possible values: ${ [ ...COMPRESSION_ALGORITHMS ] . join ( ', ' ) } ` ) ,
66+ 'gzip'
67+ )
6168 . option (
6269 '-O, --no-open' ,
6370 "Don't open report in default browser automatically."
8491 report : reportFilename ,
8592 title : reportTitle ,
8693 defaultSizes,
94+ compressionAlgorithm,
8795 logLevel,
8896 open : openBrowser ,
8997 exclude : excludeAssets
@@ -104,6 +112,9 @@ if (mode === 'server') {
104112 port = port === 'auto' ? 0 : Number ( port ) ;
105113 if ( isNaN ( port ) ) showHelp ( 'Invalid port. Should be a number or `auto`' ) ;
106114}
115+ if ( ! COMPRESSION_ALGORITHMS . has ( compressionAlgorithm ) ) {
116+ showHelp ( `Invalid compression algorithm option. Possible values are: ${ [ ...COMPRESSION_ALGORITHMS ] . join ( ', ' ) } ` ) ;
117+ }
107118if ( ! SIZES . has ( defaultSizes ) ) showHelp ( `Invalid default sizes option. Possible values are: ${ [ ...SIZES ] . join ( ', ' ) } ` ) ;
108119
109120bundleStatsFile = resolve ( bundleStatsFile ) ;
@@ -121,6 +132,7 @@ async function parseAndAnalyse(bundleStatsFile) {
121132 port,
122133 host,
123134 defaultSizes,
135+ compressionAlgorithm,
124136 reportTitle,
125137 bundleDir,
126138 excludeAssets,
@@ -133,13 +145,15 @@ async function parseAndAnalyse(bundleStatsFile) {
133145 reportFilename : resolve ( reportFilename || 'report.html' ) ,
134146 reportTitle,
135147 defaultSizes,
148+ compressionAlgorithm,
136149 bundleDir,
137150 excludeAssets,
138151 logger : new Logger ( logLevel )
139152 } ) ;
140153 } else if ( mode === 'json' ) {
141154 viewer . generateJSONReport ( bundleStats , {
142155 reportFilename : resolve ( reportFilename || 'report.json' ) ,
156+ compressionAlgorithm,
143157 bundleDir,
144158 excludeAssets,
145159 logger : new Logger ( logLevel )
@@ -159,7 +173,7 @@ function showHelp(error) {
159173}
160174
161175function br ( str ) {
162- return `\n${ ' ' . repeat ( 28 ) } ${ str } ` ;
176+ return `\n${ ' ' . repeat ( 32 ) } ${ str } ` ;
163177}
164178
165179function array ( ) {
0 commit comments