Skip to content

Commit b71f9ae

Browse files
committed
Drop defaultSizes: 'compressed'
but be forgiving with a gzip/brotli mismatch
1 parent b8dcd04 commit b71f9ae

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ new BundleAnalyzerPlugin(options?: object)
6161
|**`analyzerPort`**|`{Number}` or `auto`|Default: `8888`. Port that will be used in `server` mode to start HTTP server.|
6262
|**`reportFilename`**|`{String}`|Default: `report.html`. Path to bundle report file that will be generated in `static` mode. It can be either an absolute path or a path relative to a bundle output directory (which is output.path in webpack config).|
6363
|**`reportTitle`**|`{String\|function}`|Default: function that returns pretty printed current date and time. Content of the HTML `title` element; or a function of the form `() => string` that provides the content.|
64-
|**`defaultSizes`**|One of: `stat`, `parsed`, `compressed`|Default: `parsed`. Module sizes to show in report by default. [Size definitions](#size-definitions) section describes what these values mean.|
64+
|**`defaultSizes`**|One of: `stat`, `parsed`, `gzip`, `brotli`|Default: `parsed`. Module sizes to show in report by default. [Size definitions](#size-definitions) section describes what these values mean.|
6565
|**`compressionAlgorithm`**|One of: `gzip`, `brotli`|Default: `gzip`. Compression type used to calculate the compressed module sizes.|
6666
|**`openAnalyzer`**|`{Boolean}`|Default: `true`. Automatically open report in default browser.|
6767
|**`generateStatsFile`**|`{Boolean}`|Default: `false`. If `true`, webpack stats JSON file will be generated in bundle output directory|
@@ -122,7 +122,7 @@ Directory containing all generated bundles.
122122
-r, --report <file> Path to bundle report file that will be generated in `static` mode. (default: report.html)
123123
-t, --title <title> String to use in title element of html report. (default: pretty printed current date)
124124
-s, --default-sizes <type> Module sizes to show in treemap by default.
125-
Possible values: stat, parsed, compressed (default: parsed)
125+
Possible values: stat, parsed, gzip, brotli (default: parsed)
126126
--compression-algorithm <type> Compression algorithm that will be used to calculate the compressed module sizes.
127127
Possible values: gzip, brotli (default: gzip)
128128
-O, --no-open Don't open report in default browser automatically.
@@ -150,9 +150,13 @@ It is called "stat size" because it's obtained from Webpack's
150150
This is the "output" size of your files. If you're using a Webpack plugin such
151151
as Uglify, then this value will reflect the minified size of your code.
152152

153-
### `compressed`
153+
### `gzip`
154154

155-
This is the size of running the parsed bundles/modules through compression.
155+
This is the size of running the parsed bundles/modules through gzip compression.
156+
157+
### `brotli`
158+
159+
This is the size of running the parsed bundles/modules through Brotli compression.
156160

157161
<h2 align="center">Selecting Which Chunks to Display</h2>
158162

@@ -172,7 +176,7 @@ The Chunk Context Menu can be opened by right-clicking or `Ctrl`-clicking on a s
172176

173177
<h2 align="center">Troubleshooting</h2>
174178

175-
### I don't see `compressed` or `parsed` sizes, it only shows `stat` size
179+
### I don't see `gzip` or `parsed` sizes, it only shows `stat` size
176180

177181
It happens when `webpack-bundle-analyzer` analyzes files that don't actually exist in your file system, for example when you work with `webpack-dev-server` that keeps all the files in RAM. If you use `webpack-bundle-analyzer` as a plugin you won't get any errors, however if you run it via CLI you get the error message in terminal:
178182
```

src/bin/analyzer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const viewer = require('../viewer');
1010
const Logger = require('../Logger');
1111
const utils = require('../utils');
1212

13-
const SIZES = new Set(['stat', 'parsed', 'compressed']);
14-
const ACCEPTED_SIZES = new Set([...SIZES, 'gzip']);
13+
const SIZES = new Set(['stat', 'parsed', 'gzip', 'brotli']);
1514

1615
const ALGORITHMS = new Set(['gzip', 'brotli']);
1716

@@ -114,7 +113,7 @@ if (mode === 'server') {
114113
port = port === 'auto' ? 0 : Number(port);
115114
if (isNaN(port)) showHelp('Invalid port. Should be a number or `auto`');
116115
}
117-
if (!ACCEPTED_SIZES.has(defaultSizes)) {
116+
if (!SIZES.has(defaultSizes)) {
118117
showHelp(`Invalid default sizes option. Possible values are: ${[...SIZES].join(', ')}`);
119118
}
120119
if (!ALGORITHMS.has(compressionAlgorithm)) {

src/viewer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ function resolveTitle(reportTitle) {
2222
}
2323
}
2424

25-
function resolveDefaultSizes(defaultSizes) {
26-
return defaultSizes === 'compressed' ? 'gzip' : defaultSizes;
25+
function resolveDefaultSizes(defaultSizes, compressionAlgorithm) {
26+
if (['gzip', 'brotli'].includes(defaultSizes)) return compressionAlgorithm;
27+
return defaultSizes;
2728
}
2829

2930
module.exports = {
@@ -64,7 +65,7 @@ async function startServer(bundleStats, opts) {
6465
mode: 'server',
6566
title: resolveTitle(reportTitle),
6667
chartData,
67-
defaultSizes: resolveDefaultSizes(defaultSizes),
68+
defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
6869
compressionAlgorithm,
6970
enableWebSocket: true
7071
});
@@ -147,7 +148,7 @@ async function generateReport(bundleStats, opts) {
147148
mode: 'static',
148149
title: resolveTitle(reportTitle),
149150
chartData,
150-
defaultSizes: resolveDefaultSizes(defaultSizes),
151+
defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
151152
compressionAlgorithm,
152153
enableWebSocket: false
153154
});

0 commit comments

Comments
 (0)