From 03502c8eb1457d63fffb1c4bc9e72d5e1f953cd2 Mon Sep 17 00:00:00 2001 From: Alexander Wunschik Date: Thu, 23 Mar 2023 18:10:42 +0100 Subject: [PATCH] feat(reporter): show gzip info for all compressible files (fix #11288) (#12485) --- packages/vite/src/node/plugins/reporter.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index 5b8ae593bdefea..0559e02dd5cb89 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -20,6 +20,8 @@ type LogEntry = { mapSize: number | null } +const COMPRESSIBLE_ASSETS_RE = /\.(?:html|json|svg|txt|xml|xhtml)$/ + export function buildReporterPlugin(config: ResolvedConfig): Plugin { const compress = promisify(gzip) const chunkLimit = config.build.chunkSizeWarningLimit @@ -144,12 +146,14 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { } else { if (chunk.fileName.endsWith('.map')) return null const isCSS = chunk.fileName.endsWith('.css') + const isCompressible = + isCSS || COMPRESSIBLE_ASSETS_RE.test(chunk.fileName) return { name: chunk.fileName, group: isCSS ? 'CSS' : 'Assets', size: chunk.source.length, mapSize: null, // Rollup doesn't support CSS maps? - compressedSize: isCSS + compressedSize: isCompressible ? await getCompressedSize(chunk.source) : null, }