Skip to content

Commit a48bf88

Browse files
authored
perf: use Intl.NumberFormat instead of toLocaleString (#13949)
1 parent d4f13bd commit a48bf88

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
2626
const compress = promisify(gzip)
2727
const chunkLimit = config.build.chunkSizeWarningLimit
2828

29+
const numberFormatter = new Intl.NumberFormat('en', {
30+
maximumFractionDigits: 2,
31+
minimumFractionDigits: 2,
32+
})
33+
const displaySize = (bytes: number) => {
34+
return `${numberFormatter.format(bytes / 1000)} kB`
35+
}
36+
2937
const tty = process.stdout.isTTY && !process.env.CI
3038
const shouldLogInfo = LogLevels[config.logLevel || 'info'] >= LogLevels.info
3139
let hasTransformed = false
@@ -322,13 +330,6 @@ function throttle(fn: Function) {
322330
}
323331
}
324332

325-
function displaySize(bytes: number) {
326-
return `${(bytes / 1000).toLocaleString('en', {
327-
maximumFractionDigits: 2,
328-
minimumFractionDigits: 2,
329-
})} kB`
330-
}
331-
332333
function displayTime(time: number) {
333334
// display: {X}ms
334335
if (time < 1000) {

0 commit comments

Comments
 (0)