Skip to content

Commit

Permalink
perf: use Intl.NumberFormat instead of toLocaleString (#13949)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jul 25, 2023
1 parent d4f13bd commit a48bf88
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/vite/src/node/plugins/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a48bf88

Please sign in to comment.