Skip to content

Commit

Permalink
feat(reporter): show gzip info for all compressible files
Browse files Browse the repository at this point in the history
  • Loading branch information
mojoaxel committed Mar 21, 2023
1 parent 47a0f4a commit afba870
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/vite/src/node/plugins/reporter.ts
Expand Up @@ -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
Expand Down Expand Up @@ -144,14 +146,18 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
} else {
if (chunk.fileName.endsWith('.map')) return null
const isCSS = chunk.fileName.endsWith('.css')
const isCompressible = 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
? await getCompressedSize(chunk.source)
: null,
compressedSize:
isCSS || isCompressible
? await getCompressedSize(chunk.source)
: null,
}
}
},
Expand Down

0 comments on commit afba870

Please sign in to comment.