Skip to content

Commit d53b364

Browse files
committed
Improve compression ratio
1 parent b000124 commit d53b364

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/bundle-size-checker/src/viteBuilder.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import path from 'path';
22
import fs from 'fs/promises';
3-
import { gzipSync } from 'zlib';
3+
import * as zlib from 'zlib';
4+
import { promisify } from 'util';
5+
6+
const gzipAsync = promisify(zlib.gzip);
47
import { build, transformWithEsbuild } from 'vite';
58
import { visualizer } from 'rollup-plugin-visualizer';
69

@@ -199,11 +202,12 @@ async function processBundleSizes(outDir, entryName) {
199202

200203
// Calculate sizes
201204
const parsed = Buffer.byteLength(fileContent);
202-
const gzip = Buffer.byteLength(gzipSync(fileContent));
205+
const gzipBuffer = await gzipAsync(fileContent, { level: zlib.constants.Z_BEST_COMPRESSION });
206+
const gzipSize = Buffer.byteLength(gzipBuffer);
203207

204208
// Use chunk key as the name, or fallback to entry name for main chunk
205209
const chunkName = chunkKey === 'virtual:entry.tsx' ? entryName : chunkKey;
206-
return /** @type {const} */ ([chunkName, { parsed, gzip }]);
210+
return /** @type {const} */ ([chunkName, { parsed, gzip: gzipSize }]);
207211
});
208212

209213
const chunkEntries = await Promise.all(chunkPromises);

0 commit comments

Comments
 (0)