Skip to content

Commit 9724f04

Browse files
authored
feat(report): add gzip option to control gzip compression reporting (#507)
1 parent 4714ed7 commit 9724f04

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/features/report.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ interface SizeInfo {
2727
}
2828

2929
export 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+
4559
export 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

137156
async 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

Comments
 (0)