webpack-bundle-analyzer 3.6.1 → 3.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 +8 -0
- package/README.md +4 -3
- package/lib/BundleAnalyzerPlugin.js +21 -6
- package/lib/bin/analyzer.js +15 -5
- package/lib/viewer.js +26 -1
- package/package.json +1 -1
- package/public/viewer.js +2 -2
- package/public/viewer.js.map +1 -1
- package/src/BundleAnalyzerPlugin.js +13 -3
- package/src/bin/analyzer.js +17 -8
- package/src/viewer.js +16 -4
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,14 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
|
|
|
14
14
|
|
|
15
15
|
<!-- Add changelog entries for new changes under this section -->
|
|
16
16
|
|
|
17
|
+
## 3.7.0
|
|
18
|
+
|
|
19
|
+
* **New Feature**
|
|
20
|
+
* Added JSON output option (`analyzerMode: "json"` in plugin, `--mode json` in CLI) ([#341](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/341) by [@Gongreg](https://github.com/Gongreg))
|
|
21
|
+
|
|
22
|
+
* **Improvement**
|
|
23
|
+
* Persist "Show content of concatenated modules" option ([#322](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/322) by [@lorenzos](https://github.com/lorenzos))
|
|
24
|
+
|
|
17
25
|
## 3.6.1
|
|
18
26
|
|
|
19
27
|
* **Bug Fix**
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ new BundleAnalyzerPlugin(options?: object)
|
|
|
56
56
|
|
|
57
57
|
|Name|Type|Description|
|
|
58
58
|
|:--:|:--:|:----------|
|
|
59
|
-
|**`analyzerMode`**|One of: `server`, `static`, `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 `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`. |
|
|
59
|
+
|**`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`. |
|
|
60
60
|
|**`analyzerHost`**|`{String}`|Default: `127.0.0.1`. Host that will be used in `server` mode to start HTTP server.|
|
|
61
61
|
|**`analyzerPort`**|`{Number}` or `auto`|Default: `8888`. Port that will be used in `server` mode to start HTTP server.|
|
|
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).|
|
|
@@ -111,9 +111,10 @@ Directory containing all generated bundles.
|
|
|
111
111
|
|
|
112
112
|
```
|
|
113
113
|
-V, --version output the version number
|
|
114
|
-
-m, --mode <mode> Analyzer mode. Should be `server` or `
|
|
114
|
+
-m, --mode <mode> Analyzer mode. Should be `server`, `static` or `json`.
|
|
115
115
|
In `server` mode analyzer will start HTTP server to show bundle report.
|
|
116
|
-
In `static` mode single HTML file with bundle report will be generated.
|
|
116
|
+
In `static` mode single HTML file with bundle report will be generated.
|
|
117
|
+
In `json` mode single JSON file with bundle report will be generated. (default: server)
|
|
117
118
|
-h, --host <host> Host that will be used in `server` mode to start HTTP server. (default: 127.0.0.1)
|
|
118
119
|
-p, --port <n> Port that will be used in `server` mode to start HTTP server. Should be a number or `auto` (default: 8888)
|
|
119
120
|
-r, --report <file> Path to bundle report file that will be generated in `static` mode. (default: report.html)
|
|
@@ -29,7 +29,7 @@ class BundleAnalyzerPlugin {
|
|
|
29
29
|
this.opts = _objectSpread({
|
|
30
30
|
analyzerMode: 'server',
|
|
31
31
|
analyzerHost: '127.0.0.1',
|
|
32
|
-
reportFilename:
|
|
32
|
+
reportFilename: null,
|
|
33
33
|
defaultSizes: 'parsed',
|
|
34
34
|
openAnalyzer: true,
|
|
35
35
|
generateStatsFile: false,
|
|
@@ -67,6 +67,8 @@ class BundleAnalyzerPlugin {
|
|
|
67
67
|
actions.push(() => this.startAnalyzerServer(stats.toJson()));
|
|
68
68
|
} else if (this.opts.analyzerMode === 'static') {
|
|
69
69
|
actions.push(() => this.generateStaticReport(stats.toJson()));
|
|
70
|
+
} else if (this.opts.analyzerMode === 'json') {
|
|
71
|
+
actions.push(() => this.generateJSONReport(stats.toJson()));
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
if (actions.length) {
|
|
@@ -135,21 +137,34 @@ class BundleAnalyzerPlugin {
|
|
|
135
137
|
})();
|
|
136
138
|
}
|
|
137
139
|
|
|
138
|
-
|
|
140
|
+
generateJSONReport(stats) {
|
|
139
141
|
var _this3 = this;
|
|
140
142
|
|
|
141
143
|
return _asyncToGenerator(function* () {
|
|
142
|
-
yield viewer.
|
|
143
|
-
|
|
144
|
-
reportFilename: path.resolve(_this3.compiler.outputPath, _this3.opts.reportFilename),
|
|
144
|
+
yield viewer.generateJSONReport(stats, {
|
|
145
|
+
reportFilename: path.resolve(_this3.compiler.outputPath, _this3.opts.reportFilename || 'report.json'),
|
|
145
146
|
bundleDir: _this3.getBundleDirFromCompiler(),
|
|
146
147
|
logger: _this3.logger,
|
|
147
|
-
defaultSizes: _this3.opts.defaultSizes,
|
|
148
148
|
excludeAssets: _this3.opts.excludeAssets
|
|
149
149
|
});
|
|
150
150
|
})();
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
generateStaticReport(stats) {
|
|
154
|
+
var _this4 = this;
|
|
155
|
+
|
|
156
|
+
return _asyncToGenerator(function* () {
|
|
157
|
+
yield viewer.generateReport(stats, {
|
|
158
|
+
openBrowser: _this4.opts.openAnalyzer,
|
|
159
|
+
reportFilename: path.resolve(_this4.compiler.outputPath, _this4.opts.reportFilename || 'report.html'),
|
|
160
|
+
bundleDir: _this4.getBundleDirFromCompiler(),
|
|
161
|
+
logger: _this4.logger,
|
|
162
|
+
defaultSizes: _this4.opts.defaultSizes,
|
|
163
|
+
excludeAssets: _this4.opts.excludeAssets
|
|
164
|
+
});
|
|
165
|
+
})();
|
|
166
|
+
}
|
|
167
|
+
|
|
153
168
|
getBundleDirFromCompiler() {
|
|
154
169
|
switch (this.compiler.outputFileSystem.constructor.name) {
|
|
155
170
|
case 'MemoryFileSystem':
|
package/lib/bin/analyzer.js
CHANGED
|
@@ -28,9 +28,9 @@ const program = commander.version(require('../../package.json').version).usage(`
|
|
|
28
28
|
bundleStatsFile Path to Webpack Stats JSON file.
|
|
29
29
|
bundleDir Directory containing all generated bundles.
|
|
30
30
|
You should provided it if you want analyzer to show you the real parsed module sizes.
|
|
31
|
-
By default a directory of stats file is used.`).option('-m, --mode <mode>', 'Analyzer mode. Should be `server` or `
|
|
31
|
+
By default a directory of stats file is used.`).option('-m, --mode <mode>', 'Analyzer mode. Should be `server`,`static` or `json`.' + br('In `server` mode analyzer will start HTTP server to show bundle report.') + br('In `static` mode single HTML file with bundle report will be generated.') + br('In `json` mode single JSON file with bundle report will be generated.'), 'server').option( // Had to make `host` parameter optional in order to let `-h` flag output help message
|
|
32
32
|
// Fixes https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/239
|
|
33
|
-
'-h, --host [host]', 'Host that will be used in `server` mode to start HTTP server.', '127.0.0.1').option('-p, --port <n>', 'Port that will be used in `server` mode to start HTTP server.', 8888).option('-r, --report <file>', 'Path to bundle report file that will be generated in `static` mode.'
|
|
33
|
+
'-h, --host [host]', 'Host that will be used in `server` mode to start HTTP server.', '127.0.0.1').option('-p, --port <n>', 'Port that will be used in `server` mode to start HTTP server.', 8888).option('-r, --report <file>', 'Path to bundle report file that will be generated in `static` mode.').option('-s, --default-sizes <type>', 'Module sizes to show in treemap by default.' + br(`Possible values: ${[...SIZES].join(', ')}`), 'parsed').option('-O, --no-open', "Don't open report in default browser automatically.").option('-e, --exclude <regexp>', 'Assets that should be excluded from the report.' + br('Can be specified multiple times.'), array()).option('-l, --log-level <level>', 'Log level.' + br(`Possible values: ${[...Logger.levels].join(', ')}`), Logger.defaultLevel).parse(process.argv);
|
|
34
34
|
let {
|
|
35
35
|
mode,
|
|
36
36
|
host,
|
|
@@ -44,7 +44,10 @@ let {
|
|
|
44
44
|
} = program;
|
|
45
45
|
const logger = new Logger(logLevel);
|
|
46
46
|
if (!bundleStatsFile) showHelp('Provide path to Webpack Stats file as first argument');
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
if (mode !== 'server' && mode !== 'static' && mode !== 'json') {
|
|
49
|
+
showHelp('Invalid mode. Should be either `server`, `static` or `json`.');
|
|
50
|
+
}
|
|
48
51
|
|
|
49
52
|
if (mode === 'server') {
|
|
50
53
|
if (!host) showHelp('Invalid host name');
|
|
@@ -75,15 +78,22 @@ if (mode === 'server') {
|
|
|
75
78
|
excludeAssets,
|
|
76
79
|
logger: new Logger(logLevel)
|
|
77
80
|
});
|
|
78
|
-
} else {
|
|
81
|
+
} else if (mode === 'static') {
|
|
79
82
|
viewer.generateReport(bundleStats, {
|
|
80
83
|
openBrowser,
|
|
81
|
-
reportFilename: resolve(reportFilename),
|
|
84
|
+
reportFilename: resolve(reportFilename || 'report.html'),
|
|
82
85
|
defaultSizes,
|
|
83
86
|
bundleDir,
|
|
84
87
|
excludeAssets,
|
|
85
88
|
logger: new Logger(logLevel)
|
|
86
89
|
});
|
|
90
|
+
} else if (mode === 'json') {
|
|
91
|
+
viewer.generateJSONReport(bundleStats, {
|
|
92
|
+
reportFilename: resolve(reportFilename || 'report.json'),
|
|
93
|
+
bundleDir,
|
|
94
|
+
excludeAssets,
|
|
95
|
+
logger: new Logger(logLevel)
|
|
96
|
+
});
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
function showHelp(error) {
|
package/lib/viewer.js
CHANGED
|
@@ -37,6 +37,7 @@ const assetsRoot = path.join(projectRoot, 'public');
|
|
|
37
37
|
module.exports = {
|
|
38
38
|
startServer,
|
|
39
39
|
generateReport,
|
|
40
|
+
generateJSONReport,
|
|
40
41
|
// deprecated
|
|
41
42
|
start: startServer
|
|
42
43
|
};
|
|
@@ -138,7 +139,7 @@ function _generateReport() {
|
|
|
138
139
|
_generateReport = _asyncToGenerator(function* (bundleStats, opts) {
|
|
139
140
|
const {
|
|
140
141
|
openBrowser = true,
|
|
141
|
-
reportFilename
|
|
142
|
+
reportFilename,
|
|
142
143
|
bundleDir = null,
|
|
143
144
|
logger = new Logger(),
|
|
144
145
|
defaultSizes = 'parsed',
|
|
@@ -186,6 +187,30 @@ function _generateReport() {
|
|
|
186
187
|
return _generateReport.apply(this, arguments);
|
|
187
188
|
}
|
|
188
189
|
|
|
190
|
+
function generateJSONReport(_x5, _x6) {
|
|
191
|
+
return _generateJSONReport.apply(this, arguments);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function _generateJSONReport() {
|
|
195
|
+
_generateJSONReport = _asyncToGenerator(function* (bundleStats, opts) {
|
|
196
|
+
const {
|
|
197
|
+
reportFilename,
|
|
198
|
+
bundleDir = null,
|
|
199
|
+
logger = new Logger(),
|
|
200
|
+
excludeAssets = null
|
|
201
|
+
} = opts || {};
|
|
202
|
+
const chartData = getChartData({
|
|
203
|
+
logger,
|
|
204
|
+
excludeAssets
|
|
205
|
+
}, bundleStats, bundleDir);
|
|
206
|
+
if (!chartData) return;
|
|
207
|
+
mkdir.sync(path.dirname(reportFilename));
|
|
208
|
+
fs.writeFileSync(reportFilename, JSON.stringify(chartData));
|
|
209
|
+
logger.info(`${bold('Webpack Bundle Analyzer')} saved JSON report to ${bold(reportFilename)}`);
|
|
210
|
+
});
|
|
211
|
+
return _generateJSONReport.apply(this, arguments);
|
|
212
|
+
}
|
|
213
|
+
|
|
189
214
|
function getAssetContent(filename) {
|
|
190
215
|
const assetPath = path.join(assetsRoot, filename);
|
|
191
216
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-bundle-analyzer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.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",
|