From d13d1374b0f046106a5f6a11dd1fa17fc65b00c4 Mon Sep 17 00:00:00 2001 From: Ryota Watanabe <43837308+wattanx@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:40:06 +0900 Subject: [PATCH] fix: gzip and calculate. (#44) --- src/vite/report.ts | 3 ++- test/__snapshots__/index.test.ts.snap | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/vite/report.ts b/src/vite/report.ts index d56041f..b0adb4d 100644 --- a/src/vite/report.ts +++ b/src/vite/report.ts @@ -1,6 +1,7 @@ import fsp from 'node:fs/promises'; import { globby } from 'globby'; import { join } from 'pathe'; +import zlib from 'zlib'; import { getOptions } from '../utils'; export async function getClientStats() { @@ -24,7 +25,7 @@ async function analyzeSizes(pattern: string | string[], rootDir: string) { )?.isSymbolicLink(); if (!isSymlink) { - const bytes = Buffer.byteLength(await fsp.readFile(path)); + const bytes = zlib.gzipSync(await fsp.readFile(path)).byteLength; totalBytes += bytes; } } diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index 5790903..618ba83 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -18,7 +18,7 @@ exports[`ts test > Vite comparison results test 1`] = ` # Bundle Size | Route | Size (gzipped) | | --- | --- | -| \`app\` | 155.83 kB (🔴 55.83 kB) | +| \`app\` | 60.14 kB (🟢 -39.86 kB) | | \`pages/index\` | removed | | \`components/tutorial\` | removed | | \`pages/test\` | removed |"