From a48bf882e560febb9f1a1b83bfa20f52cf550d46 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 25 Jul 2023 15:22:15 +0200 Subject: [PATCH] perf: use Intl.NumberFormat instead of toLocaleString (#13949) --- packages/vite/src/node/plugins/reporter.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index 2584ab5db3e654..d2d4d0705a9037 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -26,6 +26,14 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { const compress = promisify(gzip) const chunkLimit = config.build.chunkSizeWarningLimit + const numberFormatter = new Intl.NumberFormat('en', { + maximumFractionDigits: 2, + minimumFractionDigits: 2, + }) + const displaySize = (bytes: number) => { + return `${numberFormatter.format(bytes / 1000)} kB` + } + const tty = process.stdout.isTTY && !process.env.CI const shouldLogInfo = LogLevels[config.logLevel || 'info'] >= LogLevels.info let hasTransformed = false @@ -322,13 +330,6 @@ function throttle(fn: Function) { } } -function displaySize(bytes: number) { - return `${(bytes / 1000).toLocaleString('en', { - maximumFractionDigits: 2, - minimumFractionDigits: 2, - })} kB` -} - function displayTime(time: number) { // display: {X}ms if (time < 1000) {