webpack-bundle-analyzer 4.9.0 → 5.2.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/README.md +34 -23
- package/lib/BundleAnalyzerPlugin.js +7 -28
- package/lib/Logger.js +2 -9
- package/lib/analyzer.js +110 -89
- package/lib/bin/analyzer.js +17 -22
- package/lib/index.js +0 -1
- package/lib/parseUtils.js +61 -81
- package/lib/sizeUtils.js +19 -0
- package/lib/statsUtils.js +0 -16
- package/lib/template.js +9 -14
- package/lib/tree/BaseFolder.js +6 -30
- package/lib/tree/ConcatenatedModule.js +21 -39
- package/lib/tree/ContentFolder.js +11 -12
- package/lib/tree/ContentModule.js +9 -12
- package/lib/tree/Folder.js +31 -31
- package/lib/tree/Module.js +28 -27
- package/lib/tree/Node.js +0 -7
- package/lib/tree/utils.js +8 -12
- package/lib/utils.js +4 -16
- package/lib/viewer.js +27 -37
- package/package.json +31 -26
- package/public/viewer.js +3 -3
- package/public/viewer.js.map +1 -1
- package/CHANGELOG.md +0 -501
package/lib/utils.js
CHANGED
|
@@ -4,45 +4,35 @@ const {
|
|
|
4
4
|
inspect,
|
|
5
5
|
types
|
|
6
6
|
} = require('util');
|
|
7
|
-
|
|
8
|
-
const _ = require('lodash');
|
|
9
|
-
|
|
10
7
|
const opener = require('opener');
|
|
11
|
-
|
|
12
8
|
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
13
9
|
exports.createAssetsFilter = createAssetsFilter;
|
|
14
|
-
|
|
15
10
|
function createAssetsFilter(excludePatterns) {
|
|
16
|
-
const excludeFunctions =
|
|
11
|
+
const excludeFunctions = (Array.isArray(excludePatterns) ? excludePatterns : [excludePatterns]).filter(Boolean).map(pattern => {
|
|
17
12
|
if (typeof pattern === 'string') {
|
|
18
13
|
pattern = new RegExp(pattern, 'u');
|
|
19
14
|
}
|
|
20
|
-
|
|
21
15
|
if (types.isRegExp(pattern)) {
|
|
22
16
|
return asset => pattern.test(asset);
|
|
23
17
|
}
|
|
24
|
-
|
|
25
18
|
if (typeof pattern !== 'function') {
|
|
26
19
|
throw new TypeError(`Pattern should be either string, RegExp or a function, but "${inspect(pattern, {
|
|
27
20
|
depth: 0
|
|
28
21
|
})}" got.`);
|
|
29
22
|
}
|
|
30
|
-
|
|
31
23
|
return pattern;
|
|
32
|
-
})
|
|
33
|
-
|
|
24
|
+
});
|
|
34
25
|
if (excludeFunctions.length) {
|
|
35
26
|
return asset => excludeFunctions.every(fn => fn(asset) !== true);
|
|
36
27
|
} else {
|
|
37
28
|
return () => true;
|
|
38
29
|
}
|
|
39
30
|
}
|
|
31
|
+
|
|
40
32
|
/**
|
|
41
33
|
* @desc get string of current time
|
|
42
34
|
* format: dd/MMM HH:mm
|
|
43
35
|
* */
|
|
44
|
-
|
|
45
|
-
|
|
46
36
|
exports.defaultTitle = function () {
|
|
47
37
|
const time = new Date();
|
|
48
38
|
const year = time.getFullYear();
|
|
@@ -53,7 +43,6 @@ exports.defaultTitle = function () {
|
|
|
53
43
|
const currentTime = `${day} ${month} ${year} at ${hour}:${minute}`;
|
|
54
44
|
return `${process.env.npm_package_name || 'Webpack Bundle Analyzer'} [${currentTime}]`;
|
|
55
45
|
};
|
|
56
|
-
|
|
57
46
|
exports.defaultAnalyzerUrl = function (options) {
|
|
58
47
|
const {
|
|
59
48
|
listenHost,
|
|
@@ -61,11 +50,10 @@ exports.defaultAnalyzerUrl = function (options) {
|
|
|
61
50
|
} = options;
|
|
62
51
|
return `http://${listenHost}:${boundAddress.port}`;
|
|
63
52
|
};
|
|
53
|
+
|
|
64
54
|
/**
|
|
65
55
|
* Calls opener on a URI, but silently try / catches it.
|
|
66
56
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
57
|
exports.open = function (uri, logger) {
|
|
70
58
|
try {
|
|
71
59
|
opener(uri);
|
package/lib/viewer.js
CHANGED
|
@@ -1,35 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
|
-
|
|
5
4
|
const fs = require('fs');
|
|
6
|
-
|
|
7
5
|
const http = require('http');
|
|
8
|
-
|
|
9
6
|
const WebSocket = require('ws');
|
|
10
|
-
|
|
11
7
|
const sirv = require('sirv');
|
|
12
|
-
|
|
13
|
-
const _ = require('lodash');
|
|
14
|
-
|
|
15
8
|
const {
|
|
16
9
|
bold
|
|
17
|
-
} = require('
|
|
18
|
-
|
|
10
|
+
} = require('picocolors');
|
|
19
11
|
const Logger = require('./Logger');
|
|
20
|
-
|
|
21
12
|
const analyzer = require('./analyzer');
|
|
22
|
-
|
|
23
13
|
const {
|
|
24
14
|
open
|
|
25
15
|
} = require('./utils');
|
|
26
|
-
|
|
27
16
|
const {
|
|
28
17
|
renderViewer
|
|
29
18
|
} = require('./template');
|
|
30
|
-
|
|
31
19
|
const projectRoot = path.resolve(__dirname, '..');
|
|
32
|
-
|
|
33
20
|
function resolveTitle(reportTitle) {
|
|
34
21
|
if (typeof reportTitle === 'function') {
|
|
35
22
|
return reportTitle();
|
|
@@ -37,7 +24,10 @@ function resolveTitle(reportTitle) {
|
|
|
37
24
|
return reportTitle;
|
|
38
25
|
}
|
|
39
26
|
}
|
|
40
|
-
|
|
27
|
+
function resolveDefaultSizes(defaultSizes, compressionAlgorithm) {
|
|
28
|
+
if (['gzip', 'brotli', 'zstd'].includes(defaultSizes)) return compressionAlgorithm;
|
|
29
|
+
return defaultSizes;
|
|
30
|
+
}
|
|
41
31
|
module.exports = {
|
|
42
32
|
startServer,
|
|
43
33
|
generateReport,
|
|
@@ -46,7 +36,6 @@ module.exports = {
|
|
|
46
36
|
// deprecated
|
|
47
37
|
start: startServer
|
|
48
38
|
};
|
|
49
|
-
|
|
50
39
|
async function startServer(bundleStats, opts) {
|
|
51
40
|
const {
|
|
52
41
|
port = 8888,
|
|
@@ -55,13 +44,15 @@ async function startServer(bundleStats, opts) {
|
|
|
55
44
|
bundleDir = null,
|
|
56
45
|
logger = new Logger(),
|
|
57
46
|
defaultSizes = 'parsed',
|
|
47
|
+
compressionAlgorithm,
|
|
58
48
|
excludeAssets = null,
|
|
59
49
|
reportTitle,
|
|
60
50
|
analyzerUrl
|
|
61
51
|
} = opts || {};
|
|
62
52
|
const analyzerOpts = {
|
|
63
53
|
logger,
|
|
64
|
-
excludeAssets
|
|
54
|
+
excludeAssets,
|
|
55
|
+
compressionAlgorithm
|
|
65
56
|
};
|
|
66
57
|
let chartData = getChartData(analyzerOpts, bundleStats, bundleDir);
|
|
67
58
|
const entrypoints = getEntrypoints(bundleStats);
|
|
@@ -77,7 +68,8 @@ async function startServer(bundleStats, opts) {
|
|
|
77
68
|
title: resolveTitle(reportTitle),
|
|
78
69
|
chartData,
|
|
79
70
|
entrypoints,
|
|
80
|
-
defaultSizes,
|
|
71
|
+
defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
|
|
72
|
+
compressionAlgorithm,
|
|
81
73
|
enableWebSocket: true
|
|
82
74
|
});
|
|
83
75
|
res.writeHead(200, {
|
|
@@ -97,7 +89,6 @@ async function startServer(bundleStats, opts) {
|
|
|
97
89
|
boundAddress: server.address()
|
|
98
90
|
});
|
|
99
91
|
logger.info(`${bold('Webpack Bundle Analyzer')} is started at ${bold(url)}\n` + `Use ${bold('Ctrl+C')} to close it`);
|
|
100
|
-
|
|
101
92
|
if (openBrowser) {
|
|
102
93
|
open(url, logger);
|
|
103
94
|
}
|
|
@@ -118,7 +109,6 @@ async function startServer(bundleStats, opts) {
|
|
|
118
109
|
http: server,
|
|
119
110
|
updateChartData
|
|
120
111
|
};
|
|
121
|
-
|
|
122
112
|
function updateChartData(bundleStats) {
|
|
123
113
|
const newChartData = getChartData(analyzerOpts, bundleStats, bundleDir);
|
|
124
114
|
if (!newChartData) return;
|
|
@@ -133,7 +123,6 @@ async function startServer(bundleStats, opts) {
|
|
|
133
123
|
});
|
|
134
124
|
}
|
|
135
125
|
}
|
|
136
|
-
|
|
137
126
|
async function generateReport(bundleStats, opts) {
|
|
138
127
|
const {
|
|
139
128
|
openBrowser = true,
|
|
@@ -142,11 +131,13 @@ async function generateReport(bundleStats, opts) {
|
|
|
142
131
|
bundleDir = null,
|
|
143
132
|
logger = new Logger(),
|
|
144
133
|
defaultSizes = 'parsed',
|
|
134
|
+
compressionAlgorithm,
|
|
145
135
|
excludeAssets = null
|
|
146
136
|
} = opts || {};
|
|
147
137
|
const chartData = getChartData({
|
|
148
138
|
logger,
|
|
149
|
-
excludeAssets
|
|
139
|
+
excludeAssets,
|
|
140
|
+
compressionAlgorithm
|
|
150
141
|
}, bundleStats, bundleDir);
|
|
151
142
|
const entrypoints = getEntrypoints(bundleStats);
|
|
152
143
|
if (!chartData) return;
|
|
@@ -155,7 +146,8 @@ async function generateReport(bundleStats, opts) {
|
|
|
155
146
|
title: resolveTitle(reportTitle),
|
|
156
147
|
chartData,
|
|
157
148
|
entrypoints,
|
|
158
|
-
defaultSizes,
|
|
149
|
+
defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
|
|
150
|
+
compressionAlgorithm,
|
|
159
151
|
enableWebSocket: false
|
|
160
152
|
});
|
|
161
153
|
const reportFilepath = path.resolve(bundleDir || process.cwd(), reportFilename);
|
|
@@ -164,22 +156,22 @@ async function generateReport(bundleStats, opts) {
|
|
|
164
156
|
});
|
|
165
157
|
fs.writeFileSync(reportFilepath, reportHtml);
|
|
166
158
|
logger.info(`${bold('Webpack Bundle Analyzer')} saved report to ${bold(reportFilepath)}`);
|
|
167
|
-
|
|
168
159
|
if (openBrowser) {
|
|
169
160
|
open(`file://${reportFilepath}`, logger);
|
|
170
161
|
}
|
|
171
162
|
}
|
|
172
|
-
|
|
173
163
|
async function generateJSONReport(bundleStats, opts) {
|
|
174
164
|
const {
|
|
175
165
|
reportFilename,
|
|
176
166
|
bundleDir = null,
|
|
177
167
|
logger = new Logger(),
|
|
178
|
-
excludeAssets = null
|
|
168
|
+
excludeAssets = null,
|
|
169
|
+
compressionAlgorithm
|
|
179
170
|
} = opts || {};
|
|
180
171
|
const chartData = getChartData({
|
|
181
172
|
logger,
|
|
182
|
-
excludeAssets
|
|
173
|
+
excludeAssets,
|
|
174
|
+
compressionAlgorithm
|
|
183
175
|
}, bundleStats, bundleDir);
|
|
184
176
|
if (!chartData) return;
|
|
185
177
|
await fs.promises.mkdir(path.dirname(reportFilename), {
|
|
@@ -188,33 +180,31 @@ async function generateJSONReport(bundleStats, opts) {
|
|
|
188
180
|
await fs.promises.writeFile(reportFilename, JSON.stringify(chartData));
|
|
189
181
|
logger.info(`${bold('Webpack Bundle Analyzer')} saved JSON report to ${bold(reportFilename)}`);
|
|
190
182
|
}
|
|
191
|
-
|
|
192
183
|
function getChartData(analyzerOpts, ...args) {
|
|
193
184
|
let chartData;
|
|
194
185
|
const {
|
|
195
186
|
logger
|
|
196
187
|
} = analyzerOpts;
|
|
197
|
-
|
|
198
188
|
try {
|
|
199
189
|
chartData = analyzer.getViewerData(...args, analyzerOpts);
|
|
200
190
|
} catch (err) {
|
|
201
|
-
logger.error(`
|
|
191
|
+
logger.error(`Couldn't analyze webpack bundle:\n${err}`);
|
|
202
192
|
logger.debug(err.stack);
|
|
203
193
|
chartData = null;
|
|
204
194
|
}
|
|
205
195
|
|
|
206
|
-
|
|
207
|
-
|
|
196
|
+
// chartData can either be an array (bundleInfo[]) or null. It can't be an plain object anyway
|
|
197
|
+
if (
|
|
198
|
+
// analyzer.getViewerData() doesn't failed in the previous step
|
|
199
|
+
chartData && !Array.isArray(chartData)) {
|
|
200
|
+
logger.error("Couldn't find any javascript bundles in provided stats file");
|
|
208
201
|
chartData = null;
|
|
209
202
|
}
|
|
210
|
-
|
|
211
203
|
return chartData;
|
|
212
204
|
}
|
|
213
|
-
|
|
214
205
|
function getEntrypoints(bundleStats) {
|
|
215
|
-
if (bundleStats === null || bundleStats === undefined) {
|
|
206
|
+
if (bundleStats === null || bundleStats === undefined || !bundleStats.entrypoints) {
|
|
216
207
|
return [];
|
|
217
208
|
}
|
|
218
|
-
|
|
219
|
-
return Object.values(bundleStats.entrypoints || {}).map(entrypoint => entrypoint.name);
|
|
209
|
+
return Object.values(bundleStats.entrypoints).map(entrypoint => entrypoint.name);
|
|
220
210
|
}
|
package/package.json
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-bundle-analyzer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.2.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",
|
|
7
|
-
"homepage": "https://github.com/webpack
|
|
8
|
-
"changelog": "https://github.com/webpack
|
|
7
|
+
"homepage": "https://github.com/webpack/webpack-bundle-analyzer",
|
|
8
|
+
"changelog": "https://github.com/webpack/webpack-bundle-analyzer/blob/main/CHANGELOG.md",
|
|
9
9
|
"bugs": {
|
|
10
|
-
"url": "https://github.com/webpack
|
|
10
|
+
"url": "https://github.com/webpack/webpack-bundle-analyzer/issues"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/webpack
|
|
14
|
+
"url": "git+https://github.com/webpack/webpack-bundle-analyzer.git"
|
|
15
15
|
},
|
|
16
16
|
"main": "lib/index.js",
|
|
17
17
|
"bin": "lib/bin/analyzer.js",
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
19
|
+
"node": ">= 20.9.0"
|
|
20
20
|
},
|
|
21
|
+
"packageManager": "npm@6.14.8",
|
|
21
22
|
"scripts": {
|
|
22
23
|
"start": "gulp watch",
|
|
23
24
|
"build": "gulp build",
|
|
24
25
|
"npm-publish": "npm run lint && npm run build && npm test && npm publish",
|
|
25
26
|
"lint": "eslint --ext js,jsx .",
|
|
26
27
|
"install-test-webpack-versions": "./bin/install-test-webpack-versions.sh",
|
|
27
|
-
"test": "npm run install-test-webpack-versions && jest --runInBand",
|
|
28
|
-
"test-dev": "npm run install-test-webpack-versions && jest --watch --runInBand"
|
|
28
|
+
"test": "npm run install-test-webpack-versions && NODE_OPTIONS=--openssl-legacy-provider jest --runInBand",
|
|
29
|
+
"test-dev": "npm run install-test-webpack-versions && NODE_OPTIONS=--openssl-legacy-provider jest --watch --runInBand"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"public",
|
|
@@ -35,26 +36,27 @@
|
|
|
35
36
|
"@discoveryjs/json-ext": "0.5.7",
|
|
36
37
|
"acorn": "^8.0.4",
|
|
37
38
|
"acorn-walk": "^8.0.0",
|
|
38
|
-
"chalk": "^4.1.0",
|
|
39
39
|
"commander": "^7.2.0",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"debounce": "^1.2.1",
|
|
41
|
+
"escape-string-regexp": "^4.0.0",
|
|
42
|
+
"html-escaper": "^2.0.2",
|
|
42
43
|
"opener": "^1.5.2",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
44
|
+
"picocolors": "^1.0.0",
|
|
45
|
+
"sirv": "^3.0.2",
|
|
46
|
+
"ws": "^8.19.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"@babel/core": "7.
|
|
48
|
-
"@babel/plugin-proposal-
|
|
49
|
-
"@babel/plugin-
|
|
50
|
-
"@babel/plugin-transform-runtime": "7.
|
|
51
|
-
"@babel/preset-env": "7.
|
|
52
|
-
"@babel/preset-react": "7.
|
|
53
|
-
"@babel/runtime": "7.
|
|
49
|
+
"@babel/core": "7.26.9",
|
|
50
|
+
"@babel/plugin-proposal-decorators": "7.25.9",
|
|
51
|
+
"@babel/plugin-transform-class-properties": "^7.27.1",
|
|
52
|
+
"@babel/plugin-transform-runtime": "7.26.9",
|
|
53
|
+
"@babel/preset-env": "7.26.9",
|
|
54
|
+
"@babel/preset-react": "7.26.3",
|
|
55
|
+
"@babel/runtime": "7.26.9",
|
|
54
56
|
"@carrotsearch/foamtree": "3.5.0",
|
|
55
57
|
"autoprefixer": "10.2.5",
|
|
56
58
|
"babel-eslint": "10.1.0",
|
|
57
|
-
"babel-loader": "
|
|
59
|
+
"babel-loader": "9.2.1",
|
|
58
60
|
"babel-plugin-lodash": "3.3.4",
|
|
59
61
|
"chai": "4.3.4",
|
|
60
62
|
"chai-subset": "1.6.0",
|
|
@@ -71,21 +73,24 @@
|
|
|
71
73
|
"globby": "11.0.3",
|
|
72
74
|
"gulp": "4.0.2",
|
|
73
75
|
"gulp-babel": "8.0.0",
|
|
74
|
-
"jest": "
|
|
76
|
+
"jest": "^30.2.0",
|
|
77
|
+
"lodash.memoize": "^4.1.2",
|
|
78
|
+
"lodash.merge": "^4.6.2",
|
|
79
|
+
"lodash.partial": "^4.2.1",
|
|
75
80
|
"mobx": "5.15.7",
|
|
76
81
|
"mobx-react": "6.3.1",
|
|
77
82
|
"postcss": "8.3.0",
|
|
78
83
|
"postcss-icss-values": "2.0.2",
|
|
79
84
|
"postcss-loader": "5.3.0",
|
|
80
85
|
"preact": "10.5.13",
|
|
81
|
-
"puppeteer": "
|
|
86
|
+
"puppeteer": "^24.30.0",
|
|
82
87
|
"stream-combiner2": "1.1.1",
|
|
83
88
|
"style-loader": "2.0.0",
|
|
84
89
|
"terser-webpack-plugin": "5.1.2",
|
|
85
90
|
"url-loader": "4.1.1",
|
|
86
|
-
"webpack": "5.
|
|
87
|
-
"webpack-cli": "
|
|
88
|
-
"webpack-dev-server": "
|
|
91
|
+
"webpack": "5.98.0",
|
|
92
|
+
"webpack-cli": "6.0.1",
|
|
93
|
+
"webpack-dev-server": "5.2.0"
|
|
89
94
|
},
|
|
90
95
|
"keywords": [
|
|
91
96
|
"webpack",
|