From ec1fa85fb1b0c2b3121e4376954bd3ea3e262d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Cs=C3=A1sz=C3=A1r?= Date: Sat, 10 Apr 2021 20:43:59 +0200 Subject: [PATCH] Change public API from `gzip` to `compressed` To be in line with the new `compressedSize*` options. Supports `gzip` as a synonym for backwards compatibility. Internal naming is also still `gzip*`. --- README.md | 10 +++++----- src/bin/analyzer.js | 7 +++++-- src/viewer.js | 8 ++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e522ad75..c5a5bf01 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`, `gzip`|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`, `compressed`|Default: `parsed`. Module sizes to show in report by default. [Size definitions](#size-definitions) section describes what these values mean.| |**`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| |**`statsFilename`**|`{String}`|Default: `stats.json`. Name of webpack stats JSON file that will be generated if `generateStatsFile` is `true`. It can be either an absolute path or a path relative to a bundle output directory (which is output.path in webpack config).| @@ -121,7 +121,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, gzip (default: parsed) + Possible values: stat, parsed, compressed (default: parsed) -O, --no-open Don't open report in default browser automatically. -e, --exclude <regexp> Assets that should be excluded from the report. Can be specified multiple times. @@ -147,9 +147,9 @@ 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. -### `gzip` +### `compressed` -This is the size of running the parsed bundles/modules through gzip compression. +This is the size of running the parsed bundles/modules through compression. <h2 align="center">Selecting Which Chunks to Display</h2> @@ -169,7 +169,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 `gzip` or `parsed` sizes, it only shows `stat` size +### I don't see `compressed` 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 5303578c..0e9f6702 100755 --- a/src/bin/analyzer.js +++ b/src/bin/analyzer.js @@ -10,7 +10,8 @@ const viewer = require('../viewer'); const Logger = require('../Logger'); const utils = require('../utils'); -const SIZES = new Set(['stat', 'parsed', 'gzip']); +const SIZES = new Set(['stat', 'parsed', 'compressed']); +const ACCEPTED_SIZES = new Set([...SIZES, 'gzip']); const program = commander .version(require('../../package.json').version) @@ -104,7 +105,9 @@ if (mode === 'server') { port = port === 'auto' ? 0 : Number(port); if (isNaN(port)) showHelp('Invalid port. Should be a number or `auto`'); } -if (!SIZES.has(defaultSizes)) showHelp(`Invalid default sizes option. Possible values are: ${[...SIZES].join(', ')}`); +if (!ACCEPTED_SIZES.has(defaultSizes)) { + showHelp(`Invalid default sizes option. Possible values are: ${[...SIZES].join(', ')}`); +} bundleStatsFile = resolve(bundleStatsFile); diff --git a/src/viewer.js b/src/viewer.js index 87304f54..2068c929 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -22,6 +22,10 @@ function resolveTitle(reportTitle) { } } +function resolveDefaultSizes(defaultSizes) { + return defaultSizes === 'compressed' ? 'gzip' : defaultSizes; +} + module.exports = { startServer, generateReport, @@ -59,7 +63,7 @@ async function startServer(bundleStats, opts) { mode: 'server', title: resolveTitle(reportTitle), chartData, - defaultSizes, + defaultSizes: resolveDefaultSizes(defaultSizes), enableWebSocket: true }); res.writeHead(200, {'Content-Type': 'text/html'}); @@ -140,7 +144,7 @@ async function generateReport(bundleStats, opts) { mode: 'static', title: resolveTitle(reportTitle), chartData, - defaultSizes, + defaultSizes: resolveDefaultSizes(defaultSizes), enableWebSocket: false }); const reportFilepath = path.resolve(bundleDir || process.cwd(), reportFilename);