webpack-bundle-analyzer 4.6.1 → 4.7.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,11 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
12
12
 
13
13
  ## UNRELEASED
14
14
 
15
+ ## 4.7.0
16
+
17
+ * **New Feature**
18
+ * Add the ability to filter to displaying only initial chunks per entrypoint ([#519](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/519) by [@pas-trop-de-zele](https://github.com/pas-trop-de-zele))
19
+
15
20
  ## 4.6.1
16
21
 
17
22
  * **Bug Fix**
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  [![npm][npm]][npm-url]
2
2
  [![node][node]][node-url]
3
- [![deps][deps]][deps-url]
4
3
  [![tests][tests]][tests-url]
5
4
  [![downloads][downloads]][downloads-url]
6
5
 
@@ -211,9 +210,6 @@ To get more information about it you can read [issue #147](https://github.com/we
211
210
  [node]: https://img.shields.io/node/v/webpack-bundle-analyzer.svg
212
211
  [node-url]: https://nodejs.org
213
212
 
214
- [deps]: https://david-dm.org/webpack-contrib/webpack-bundle-analyzer.svg
215
- [deps-url]: https://david-dm.org/webpack-contrib/webpack-bundle-analyzer
216
-
217
213
  [tests]: http://img.shields.io/travis/webpack-contrib/webpack-bundle-analyzer.svg
218
214
  [tests-url]: https://travis-ci.org/webpack-contrib/webpack-bundle-analyzer
219
215
 
package/lib/analyzer.js CHANGED
@@ -155,18 +155,24 @@ function getViewerData(bundleStats, bundleDir, opts) {
155
155
  asset.tree = createModulesTree(asset.modules);
156
156
  return result;
157
157
  }, {});
158
- return Object.entries(assets).map(([filename, asset]) => ({
159
- label: filename,
160
- isAsset: true,
161
- // Not using `asset.size` here provided by Webpack because it can be very confusing when `UglifyJsPlugin` is used.
162
- // In this case all module sizes from stats file will represent unminified module sizes, but `asset.size` will
163
- // be the size of minified bundle.
164
- // Using `asset.size` only if current asset doesn't contain any modules (resulting size equals 0)
165
- statSize: asset.tree.size || asset.size,
166
- parsedSize: asset.parsedSize,
167
- gzipSize: asset.gzipSize,
168
- groups: _.invokeMap(asset.tree.children, 'toChartData')
169
- }));
158
+ const chunkToInitialByEntrypoint = getChunkToInitialByEntrypoint(bundleStats);
159
+ return Object.entries(assets).map(([filename, asset]) => {
160
+ var _chunkToInitialByEntr;
161
+
162
+ return {
163
+ label: filename,
164
+ isAsset: true,
165
+ // Not using `asset.size` here provided by Webpack because it can be very confusing when `UglifyJsPlugin` is used.
166
+ // In this case all module sizes from stats file will represent unminified module sizes, but `asset.size` will
167
+ // be the size of minified bundle.
168
+ // Using `asset.size` only if current asset doesn't contain any modules (resulting size equals 0)
169
+ statSize: asset.tree.size || asset.size,
170
+ parsedSize: asset.parsedSize,
171
+ gzipSize: asset.gzipSize,
172
+ groups: _.invokeMap(asset.tree.children, 'toChartData'),
173
+ isInitialByEntrypoint: (_chunkToInitialByEntr = chunkToInitialByEntrypoint[filename]) !== null && _chunkToInitialByEntr !== void 0 ? _chunkToInitialByEntr : {}
174
+ };
175
+ });
170
176
  }
171
177
 
172
178
  function readStatsFromFile(filename) {
@@ -200,4 +206,23 @@ function createModulesTree(modules) {
200
206
  modules.forEach(module => root.addModule(module));
201
207
  root.mergeNestedFolders();
202
208
  return root;
203
- }
209
+ }
210
+
211
+ function getChunkToInitialByEntrypoint(bundleStats) {
212
+ if (bundleStats == null) {
213
+ return {};
214
+ }
215
+
216
+ const chunkToEntrypointInititalMap = {};
217
+ Object.values(bundleStats.entrypoints || {}).forEach(entrypoint => {
218
+ for (const asset of entrypoint.assets) {
219
+ var _chunkToEntrypointIni;
220
+
221
+ chunkToEntrypointInititalMap[asset.name] = (_chunkToEntrypointIni = chunkToEntrypointInititalMap[asset.name]) !== null && _chunkToEntrypointIni !== void 0 ? _chunkToEntrypointIni : {};
222
+ chunkToEntrypointInititalMap[asset.name][entrypoint.name] = true;
223
+ }
224
+ });
225
+ return chunkToEntrypointInititalMap;
226
+ }
227
+
228
+ ;
package/lib/template.js CHANGED
@@ -45,6 +45,7 @@ function renderViewer({
45
45
  title,
46
46
  enableWebSocket,
47
47
  chartData,
48
+ entrypoints,
48
49
  defaultSizes,
49
50
  mode
50
51
  } = {}) {
@@ -66,6 +67,7 @@ function renderViewer({
66
67
  <div id="app"></div>
67
68
  <script>
68
69
  window.chartData = ${escapeJson(chartData)};
70
+ window.entrypoints = ${escapeJson(entrypoints)};
69
71
  window.defaultSizes = ${escapeJson(defaultSizes)};
70
72
  </script>
71
73
  </body>
package/lib/viewer.js CHANGED
@@ -42,6 +42,7 @@ module.exports = {
42
42
  startServer,
43
43
  generateReport,
44
44
  generateJSONReport,
45
+ getEntrypoints,
45
46
  // deprecated
46
47
  start: startServer
47
48
  };
@@ -63,6 +64,7 @@ async function startServer(bundleStats, opts) {
63
64
  excludeAssets
64
65
  };
65
66
  let chartData = getChartData(analyzerOpts, bundleStats, bundleDir);
67
+ const entrypoints = getEntrypoints(bundleStats);
66
68
  if (!chartData) return;
67
69
  const sirvMiddleware = sirv(`${projectRoot}/public`, {
68
70
  // disables caching and traverse the file system on every request
@@ -74,6 +76,7 @@ async function startServer(bundleStats, opts) {
74
76
  mode: 'server',
75
77
  title: resolveTitle(reportTitle),
76
78
  chartData,
79
+ entrypoints,
77
80
  defaultSizes,
78
81
  enableWebSocket: true
79
82
  });
@@ -145,11 +148,13 @@ async function generateReport(bundleStats, opts) {
145
148
  logger,
146
149
  excludeAssets
147
150
  }, bundleStats, bundleDir);
151
+ const entrypoints = getEntrypoints(bundleStats);
148
152
  if (!chartData) return;
149
153
  const reportHtml = renderViewer({
150
154
  mode: 'static',
151
155
  title: resolveTitle(reportTitle),
152
156
  chartData,
157
+ entrypoints,
153
158
  defaultSizes,
154
159
  enableWebSocket: false
155
160
  });
@@ -204,4 +209,12 @@ function getChartData(analyzerOpts, ...args) {
204
209
  }
205
210
 
206
211
  return chartData;
212
+ }
213
+
214
+ function getEntrypoints(bundleStats) {
215
+ if (bundleStats === null || bundleStats === undefined) {
216
+ return [];
217
+ }
218
+
219
+ return Object.values(bundleStats.entrypoints || {}).map(entrypoint => entrypoint.name);
207
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-bundle-analyzer",
3
- "version": "4.6.1",
3
+ "version": "4.7.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",