@@ -27,6 +27,14 @@ interface SizeInfo {
2727}
2828
2929export interface ReportOptions {
30+ /**
31+ * Enable/disable gzip-compressed size reporting.
32+ * Compressing large output files can be slow, so disabling this may increase build performance for large projects.
33+ *
34+ * @default true
35+ */
36+ gzip ?: boolean
37+
3038 /**
3139 * Enable/disable brotli-compressed size reporting.
3240 * Compressing large output files can be slow, so disabling this may increase build performance for large projects.
@@ -42,14 +50,25 @@ export interface ReportOptions {
4250 maxCompressSize ?: number
4351}
4452
53+ const defaultOptions = {
54+ gzip : true ,
55+ brotli : false ,
56+ maxCompressSize : 1_000_000 ,
57+ }
58+
4559export function ReportPlugin (
46- options : ReportOptions ,
60+ userOptions : ReportOptions ,
4761 logger : Logger ,
4862 cwd : string ,
4963 cjsDts ?: boolean ,
5064 name ?: string ,
5165 isMultiFormat ?: boolean ,
5266) : Plugin {
67+ const options = {
68+ ...defaultOptions ,
69+ ...userOptions ,
70+ }
71+
5372 return {
5473 name : 'tsdown:report' ,
5574 async writeBundle ( outputOptions , bundle ) {
@@ -117,7 +136,7 @@ export function ReportPlugin(
117136 filenameColor ( ( size . isEntry ? bold : noop ) ( size . filename ) ) ,
118137 ` ` . repeat ( filenameLength - size . filename . length ) ,
119138 dim ( size . rawText ) ,
120- size . gzipText && dim `│ gzip: ${ size . gzipText } ` ,
139+ options . gzip && size . gzipText && dim `│ gzip: ${ size . gzipText } ` ,
121140 options . brotli &&
122141 size . brotliText &&
123142 dim `│ brotli: ${ size . brotliText } ` ,
@@ -135,7 +154,7 @@ export function ReportPlugin(
135154}
136155
137156async function calcSize (
138- options : ReportOptions ,
157+ options : Required < ReportOptions > ,
139158 chunk : OutputAsset | OutputChunk ,
140159) : Promise < SizeInfo > {
141160 debug ( `Calculating size for` , chunk . fileName )
@@ -147,12 +166,13 @@ async function calcSize(
147166
148167 let gzip : number = Infinity
149168 let brotli : number = Infinity
150- if ( raw > ( options . maxCompressSize ?? 1_000_000 ) ) {
169+ if ( raw > options . maxCompressSize ) {
151170 debug ( chunk . fileName , 'file size exceeds limit, skip gzip/brotli' )
152171 } else {
153- gzip = ( await gzipAsync ( content ) ) . length
154- debug ( '[gzip]' , chunk . fileName , gzip )
155-
172+ if ( options . gzip ) {
173+ gzip = ( await gzipAsync ( content ) ) . length
174+ debug ( '[gzip]' , chunk . fileName , gzip )
175+ }
156176 if ( options . brotli ) {
157177 brotli = ( await brotliCompressAsync ( content ) ) . length
158178 debug ( '[brotli]' , chunk . fileName , brotli )
0 commit comments