Skip to content

Commit db3c324

Browse files
authored
fix: brotli skipped is printed when build.brotliSize is false (vitejs#1912)
1 parent 9726386 commit db3c324

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/vite/src/node/plugins/reporter.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ const writeColors = {
2525
export function buildReporterPlugin(config: ResolvedConfig): Plugin {
2626
const chunkLimit = config.build.chunkSizeWarningLimit
2727

28+
function isLarge(code: string | Uint8Array): boolean {
29+
// bail out on particularly large chunks
30+
return code.length / 1024 > chunkLimit
31+
}
32+
2833
async function getCompressedSize(code: string | Uint8Array): Promise<string> {
2934
if (config.build.ssr || !config.build.brotliSize) {
3035
return ''
3136
}
37+
if (isLarge(code)) {
38+
return ' / brotli: skipped (large chunk)'
39+
}
3240
return ` / brotli: ${(
3341
(await size(typeof code === 'string' ? code : Buffer.from(code))) / 1024
3442
).toFixed(2)}kb`
@@ -147,17 +155,13 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
147155
Object.keys(output).map(async (file) => {
148156
const chunk = output[file]
149157
if (chunk.type === 'chunk') {
150-
// bail out on particularly large chunks
151-
const isLarge = chunk.code.length / 1024 > chunkLimit
152158
const log = async () => {
153159
printFileInfo(
154160
chunk.fileName,
155161
chunk.code,
156162
WriteType.JS,
157163
longest,
158-
isLarge
159-
? ' / brotli: skipped (large chunk)'
160-
: await getCompressedSize(chunk.code)
164+
await getCompressedSize(chunk.code)
161165
)
162166
if (chunk.map) {
163167
printFileInfo(
@@ -168,7 +172,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
168172
)
169173
}
170174
}
171-
if (isLarge) {
175+
if (isLarge(chunk.code)) {
172176
hasLargeChunks = true
173177
deferredLogs.push(log)
174178
} else {

0 commit comments

Comments
 (0)