Skip to content

Commit 05c1aa8

Browse files
ArnaudBarreClay Smith
authored and
Clay Smith
committed
feat(build): Use kB in build reporter (vitejs#10982)
1 parent cdee08c commit 05c1aa8

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
2929

3030
function isLarge(code: string | Uint8Array): boolean {
3131
// bail out on particularly large chunks
32-
return code.length / 1024 > chunkLimit
32+
return code.length / 1000 > chunkLimit
3333
}
3434

3535
async function getCompressedSize(code: string | Uint8Array): Promise<string> {
3636
if (config.build.ssr || !config.build.reportCompressedSize) {
3737
return ''
3838
}
39-
return ` / gzip: ${(
39+
return ` / gzip: ${displaySize(
4040
(await compress(typeof code === 'string' ? code : Buffer.from(code)))
41-
.length / 1024
42-
).toFixed(2)} KiB`
41+
.length / 1000
42+
)}`
4343
}
4444

4545
function printFileInfo(
@@ -54,12 +54,12 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
5454
normalizePath(
5555
path.relative(config.root, path.resolve(config.root, outDir))
5656
) + '/'
57-
const kibs = content.length / 1024
58-
const sizeColor = kibs > chunkLimit ? colors.yellow : colors.dim
57+
const kB = content.length / 1000
58+
const sizeColor = kB > chunkLimit ? colors.yellow : colors.dim
5959
config.logger.info(
6060
`${colors.gray(colors.white(colors.dim(outDir)))}${writeColors[type](
6161
filePath.padEnd(maxLength + 2)
62-
)} ${sizeColor(`${kibs.toFixed(2)} KiB${compressedSize}`)}`
62+
)} ${sizeColor(`${displaySize(kB)}${compressedSize}`)}`
6363
)
6464
}
6565

@@ -201,7 +201,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
201201
} else {
202202
hasLargeChunks = Object.keys(output).some((file) => {
203203
const chunk = output[file]
204-
return chunk.type === 'chunk' && chunk.code.length / 1024 > chunkLimit
204+
return chunk.type === 'chunk' && chunk.code.length / 1000 > chunkLimit
205205
})
206206
}
207207

@@ -213,7 +213,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
213213
) {
214214
config.logger.warn(
215215
colors.yellow(
216-
`\n(!) Some chunks are larger than ${chunkLimit} KiB after minification. Consider:\n` +
216+
`\n(!) Some chunks are larger than ${chunkLimit} kBs after minification. Consider:\n` +
217217
`- Using dynamic import() to code-split the application\n` +
218218
`- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks\n` +
219219
`- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.`
@@ -244,3 +244,10 @@ function throttle(fn: Function) {
244244
}, 100)
245245
}
246246
}
247+
248+
function displaySize(kB: number) {
249+
return `${kB.toLocaleString('en', {
250+
maximumFractionDigits: 2,
251+
minimumFractionDigits: 2
252+
})} kB`
253+
}

0 commit comments

Comments
 (0)