Skip to content

Commit

Permalink
Drop defaultSizes: 'compressed'
Browse files Browse the repository at this point in the history
but be forgiving with a gzip/brotli mismatch
  • Loading branch information
dcsaszar committed Apr 15, 2021
1 parent b8dcd04 commit b71f9ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
14 changes: 9 additions & 5 deletions README.md
Expand Up @@ -61,7 +61,7 @@ new BundleAnalyzerPlugin(options?: object)
|**`analyzerPort`**|`{Number}` or `auto`|Default: `8888`. Port that will be used in `server` mode to start HTTP server.|
|**`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).|
|**`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.|
|**`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.|
|**`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.|
|**`compressionAlgorithm`**|One of: `gzip`, `brotli`|Default: `gzip`. Compression type used to calculate the compressed module sizes.|
|**`openAnalyzer`**|`{Boolean}`|Default: `true`. Automatically open report in default browser.|
|**`generateStatsFile`**|`{Boolean}`|Default: `false`. If `true`, webpack stats JSON file will be generated in bundle output directory|
Expand Down Expand Up @@ -122,7 +122,7 @@ Directory containing all generated bundles.
-r, --report <file> Path to bundle report file that will be generated in `static` mode. (default: report.html)
-t, --title <title> String to use in title element of html report. (default: pretty printed current date)
-s, --default-sizes <type> Module sizes to show in treemap by default.
Possible values: stat, parsed, compressed (default: parsed)
Possible values: stat, parsed, gzip, brotli (default: parsed)
--compression-algorithm <type> Compression algorithm that will be used to calculate the compressed module sizes.
Possible values: gzip, brotli (default: gzip)
-O, --no-open Don't open report in default browser automatically.
Expand Down Expand Up @@ -150,9 +150,13 @@ It is called "stat size" because it's obtained from Webpack's
This is the "output" size of your files. If you're using a Webpack plugin such
as Uglify, then this value will reflect the minified size of your code.

### `compressed`
### `gzip`

This is the size of running the parsed bundles/modules through compression.
This is the size of running the parsed bundles/modules through gzip compression.

### `brotli`

This is the size of running the parsed bundles/modules through Brotli compression.

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

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

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

### I don't see `compressed` or `parsed` sizes, it only shows `stat` size
### I don't see `gzip` or `parsed` sizes, it only shows `stat` size

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:
```
Expand Down
5 changes: 2 additions & 3 deletions src/bin/analyzer.js
Expand Up @@ -10,8 +10,7 @@ const viewer = require('../viewer');
const Logger = require('../Logger');
const utils = require('../utils');

const SIZES = new Set(['stat', 'parsed', 'compressed']);
const ACCEPTED_SIZES = new Set([...SIZES, 'gzip']);
const SIZES = new Set(['stat', 'parsed', 'gzip', 'brotli']);

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

Expand Down Expand Up @@ -114,7 +113,7 @@ if (mode === 'server') {
port = port === 'auto' ? 0 : Number(port);
if (isNaN(port)) showHelp('Invalid port. Should be a number or `auto`');
}
if (!ACCEPTED_SIZES.has(defaultSizes)) {
if (!SIZES.has(defaultSizes)) {
showHelp(`Invalid default sizes option. Possible values are: ${[...SIZES].join(', ')}`);
}
if (!ALGORITHMS.has(compressionAlgorithm)) {
Expand Down
9 changes: 5 additions & 4 deletions src/viewer.js
Expand Up @@ -22,8 +22,9 @@ function resolveTitle(reportTitle) {
}
}

function resolveDefaultSizes(defaultSizes) {
return defaultSizes === 'compressed' ? 'gzip' : defaultSizes;
function resolveDefaultSizes(defaultSizes, compressionAlgorithm) {
if (['gzip', 'brotli'].includes(defaultSizes)) return compressionAlgorithm;
return defaultSizes;
}

module.exports = {
Expand Down Expand Up @@ -64,7 +65,7 @@ async function startServer(bundleStats, opts) {
mode: 'server',
title: resolveTitle(reportTitle),
chartData,
defaultSizes: resolveDefaultSizes(defaultSizes),
defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
compressionAlgorithm,
enableWebSocket: true
});
Expand Down Expand Up @@ -147,7 +148,7 @@ async function generateReport(bundleStats, opts) {
mode: 'static',
title: resolveTitle(reportTitle),
chartData,
defaultSizes: resolveDefaultSizes(defaultSizes),
defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
compressionAlgorithm,
enableWebSocket: false
});
Expand Down

0 comments on commit b71f9ae

Please sign in to comment.