diff --git a/README.md b/README.md index 7d4cb15d..3ca5e1ad 100644 --- a/README.md +++ b/README.md @@ -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| @@ -122,7 +122,7 @@ Directory containing all generated bundles. -r, --report Path to bundle report file that will be generated in `static` mode. (default: report.html) -t, --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. @@ -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> @@ -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: ``` diff --git a/src/bin/analyzer.js b/src/bin/analyzer.js index 590d2f9f..814615c1 100755 --- a/src/bin/analyzer.js +++ b/src/bin/analyzer.js @@ -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']); @@ -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)) { diff --git a/src/viewer.js b/src/viewer.js index 6bf0abf1..01b79140 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -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 = { @@ -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 }); @@ -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 });