webpack-bundle-analyzer 4.7.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -12,6 +12,15 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
12
12
 
13
13
  ## UNRELEASED
14
14
 
15
+ ## 4.8.0
16
+
17
+ * **Improvement**
18
+ * Support reading large (>500MB) stats.json files ([#423](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/423) by [@henry-alakazhang](https://github.com/henry-alakazhang))
19
+ * Improve search UX by graying out non-matches ([#554](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/554) by [@starpit](https://github.com/starpit))
20
+
21
+ * **Internal**
22
+ * Add Node.js v16.x to CI and update GitHub actions ([#539](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/539) by [@amareshsm](https://github.com/amareshsm))
23
+
15
24
  ## 4.7.0
16
25
 
17
26
  * **New Feature**
package/README.md CHANGED
@@ -57,7 +57,7 @@ new BundleAnalyzerPlugin(options?: object)
57
57
  |:--:|:--:|:----------|
58
58
  |**`analyzerMode`**|One of: `server`, `static`, `json`, `disabled`|Default: `server`. In `server` mode analyzer will start HTTP server to show bundle report. In `static` mode single HTML file with bundle report will be generated. In `json` mode single JSON file with bundle report will be generated. In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`. |
59
59
  |**`analyzerHost`**|`{String}`|Default: `127.0.0.1`. Host that will be used in `server` mode to start HTTP server.|
60
- |**`analyzerPort`**|`{Number}` or `auto`|Default: `8888`. Port that will be used in `server` mode to start HTTP server.|
60
+ |**`analyzerPort`**|`{Number}` or `auto`|Default: `8888`. Port that will be used in `server` mode to start HTTP server. If `analyzerPort` is `auto`, the operating system will assign an arbitrary unused port |
61
61
  |**`analyzerUrl`**|`{Function}` called with `{ listenHost: string, listenHost: string, boundAddress: server.address}`. [server.address comes from Node.js](https://nodejs.org/api/net.html#serveraddress)| Default: `http://${listenHost}:${boundAddress.port}`. The URL printed to console with server mode.|
62
62
  |**`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).|
63
63
  |**`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.|
package/lib/analyzer.js CHANGED
@@ -8,6 +8,10 @@ const _ = require('lodash');
8
8
 
9
9
  const gzipSize = require('gzip-size');
10
10
 
11
+ const {
12
+ parseChunked
13
+ } = require('@discoveryjs/json-ext');
14
+
11
15
  const Logger = require('./Logger');
12
16
 
13
17
  const Folder = require('./tree/Folder').default;
@@ -176,7 +180,9 @@ function getViewerData(bundleStats, bundleDir, opts) {
176
180
  }
177
181
 
178
182
  function readStatsFromFile(filename) {
179
- return JSON.parse(fs.readFileSync(filename, 'utf8'));
183
+ return parseChunked(fs.createReadStream(filename, {
184
+ encoding: 'utf8'
185
+ }));
180
186
  }
181
187
 
182
188
  function getChildAssetBundles(bundleStats, assetName) {
@@ -64,45 +64,47 @@ if (mode === 'server') {
64
64
  if (!SIZES.has(defaultSizes)) showHelp(`Invalid default sizes option. Possible values are: ${[...SIZES].join(', ')}`);
65
65
  bundleStatsFile = resolve(bundleStatsFile);
66
66
  if (!bundleDir) bundleDir = dirname(bundleStatsFile);
67
- let bundleStats;
68
-
69
- try {
70
- bundleStats = analyzer.readStatsFromFile(bundleStatsFile);
71
- } catch (err) {
72
- logger.error(`Couldn't read webpack bundle stats from "${bundleStatsFile}":\n${err}`);
73
- logger.debug(err.stack);
74
- process.exit(1);
75
- }
76
-
77
- if (mode === 'server') {
78
- viewer.startServer(bundleStats, {
79
- openBrowser,
80
- port,
81
- host,
82
- defaultSizes,
83
- reportTitle,
84
- bundleDir,
85
- excludeAssets,
86
- logger: new Logger(logLevel),
87
- analyzerUrl: utils.defaultAnalyzerUrl
88
- });
89
- } else if (mode === 'static') {
90
- viewer.generateReport(bundleStats, {
91
- openBrowser,
92
- reportFilename: resolve(reportFilename || 'report.html'),
93
- reportTitle,
94
- defaultSizes,
95
- bundleDir,
96
- excludeAssets,
97
- logger: new Logger(logLevel)
98
- });
99
- } else if (mode === 'json') {
100
- viewer.generateJSONReport(bundleStats, {
101
- reportFilename: resolve(reportFilename || 'report.json'),
102
- bundleDir,
103
- excludeAssets,
104
- logger: new Logger(logLevel)
105
- });
67
+ parseAndAnalyse(bundleStatsFile);
68
+
69
+ async function parseAndAnalyse(bundleStatsFile) {
70
+ try {
71
+ const bundleStats = await analyzer.readStatsFromFile(bundleStatsFile);
72
+
73
+ if (mode === 'server') {
74
+ viewer.startServer(bundleStats, {
75
+ openBrowser,
76
+ port,
77
+ host,
78
+ defaultSizes,
79
+ reportTitle,
80
+ bundleDir,
81
+ excludeAssets,
82
+ logger: new Logger(logLevel),
83
+ analyzerUrl: utils.defaultAnalyzerUrl
84
+ });
85
+ } else if (mode === 'static') {
86
+ viewer.generateReport(bundleStats, {
87
+ openBrowser,
88
+ reportFilename: resolve(reportFilename || 'report.html'),
89
+ reportTitle,
90
+ defaultSizes,
91
+ bundleDir,
92
+ excludeAssets,
93
+ logger: new Logger(logLevel)
94
+ });
95
+ } else if (mode === 'json') {
96
+ viewer.generateJSONReport(bundleStats, {
97
+ reportFilename: resolve(reportFilename || 'report.json'),
98
+ bundleDir,
99
+ excludeAssets,
100
+ logger: new Logger(logLevel)
101
+ });
102
+ }
103
+ } catch (err) {
104
+ logger.error(`Couldn't read webpack bundle stats from "${bundleStatsFile}":\n${err}`);
105
+ logger.debug(err.stack);
106
+ process.exit(1);
107
+ }
106
108
  }
107
109
 
108
110
  function showHelp(error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-bundle-analyzer",
3
- "version": "4.7.0",
3
+ "version": "4.8.0",
4
4
  "description": "Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap",
5
5
  "author": "Yury Grunin <grunin.ya@ya.ru>",
6
6
  "license": "MIT",
@@ -32,6 +32,7 @@
32
32
  "lib"
33
33
  ],
34
34
  "dependencies": {
35
+ "@discoveryjs/json-ext": "0.5.7",
35
36
  "acorn": "^8.0.4",
36
37
  "acorn-walk": "^8.0.0",
37
38
  "chalk": "^4.1.0",
@@ -84,7 +85,7 @@
84
85
  "url-loader": "4.1.1",
85
86
  "webpack": "5.37.1",
86
87
  "webpack-cli": "3.3.12",
87
- "webpack-dev-server": "3.11.2"
88
+ "webpack-dev-server": "3.11.3"
88
89
  },
89
90
  "keywords": [
90
91
  "webpack",