webpack-bundle-analyzer 3.3.0 → 3.4.1
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 +33 -2
- package/README.md +2 -18
- package/lib/BundleAnalyzerPlugin.js +22 -9
- package/lib/bin/analyzer.js +11 -4
- package/lib/tree/ConcatenatedModule.js +3 -1
- package/lib/tree/ContentFolder.js +3 -1
- package/lib/tree/ContentModule.js +3 -1
- package/lib/tree/Folder.js +3 -1
- package/lib/viewer.js +26 -7
- package/package.json +3 -2
- package/public/viewer.js +1 -1
- package/public/viewer.js.map +1 -1
- package/src/BundleAnalyzerPlugin.js +16 -8
- package/src/bin/analyzer.js +10 -5
- package/src/viewer.js +25 -7
- package/views/script.ejs +1 -1
- package/views/viewer.ejs +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -14,10 +14,41 @@ _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.4.1
|
|
18
|
+
|
|
19
|
+
* **Bug Fix**
|
|
20
|
+
* Fix regression of requiring an object to be passed to `new BundleAnalyzerPlugin()` (issue [#300](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/300), fixed in [#302](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/302) by [@jerryOnlyZRJ](https://github.com/jerryOnlyZRJ))
|
|
21
|
+
|
|
22
|
+
## 3.4.0
|
|
23
|
+
|
|
24
|
+
* **Improvements**
|
|
25
|
+
* Add `port: 'auto'` option ([#290](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/290), [@avin-kavish](https://github.com/avin-kavish))
|
|
26
|
+
|
|
27
|
+
* **Bug Fix**
|
|
28
|
+
* Avoid mutation of the generated `stats.json` ([#293](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/293), [@wood1986](https://github.com/wood1986))
|
|
29
|
+
|
|
30
|
+
* **Internal**
|
|
31
|
+
* Use Autoprefixer ([#266](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/266), [@bregenspan](https://github.com/bregenspan))
|
|
32
|
+
* Detect `AsyncMFS` to support dev-server of Nuxt 2.5 and above ([#275](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/275), [@amoshydra](https://github.com/amoshydra))
|
|
33
|
+
|
|
34
|
+
## 3.3.2
|
|
35
|
+
|
|
36
|
+
* **Bug Fix**
|
|
37
|
+
* Fix regression with escaping internal assets ([#264](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/264), fixes [#263](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/263))
|
|
38
|
+
|
|
39
|
+
## 3.3.1
|
|
40
|
+
|
|
41
|
+
* **Improvements**
|
|
42
|
+
* Use relative links for serving internal assets ([#261](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/261), fixes [#254](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/254))
|
|
43
|
+
* Properly escape embedded JS/JSON ([#262](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/262))
|
|
44
|
+
|
|
45
|
+
* **Bug Fix**
|
|
46
|
+
* Fix showing help message on `-h` flag ([#260](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/260), fixes [#239](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/239))
|
|
47
|
+
|
|
17
48
|
## 3.3.0
|
|
18
49
|
|
|
19
50
|
* **New Feature**
|
|
20
|
-
* Show/hide chunks using context menu ([#
|
|
51
|
+
* Show/hide chunks using context menu ([#246](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/246), [@bregenspan](https://github.com/bregenspan))
|
|
21
52
|
|
|
22
53
|
* **Internal**
|
|
23
54
|
* Updated dev dependencies
|
|
@@ -25,7 +56,7 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
|
|
|
25
56
|
## 3.2.0
|
|
26
57
|
|
|
27
58
|
* **Improvements**
|
|
28
|
-
* Add support for .mjs output files ([#252](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/252), [@jlopezxs](https://github.com/jlopezxs))
|
|
59
|
+
* Add support for .mjs output files ([#252](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/252), [@jlopezxs](https://github.com/jlopezxs))
|
|
29
60
|
|
|
30
61
|
## 3.1.0
|
|
31
62
|
|
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ new BundleAnalyzerPlugin(options?: object)
|
|
|
58
58
|
|:--:|:--:|:----------|
|
|
59
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`. |
|
|
60
60
|
|**`analyzerHost`**|`{String}`|Default: `127.0.0.1`. Host that will be used in `server` mode to start HTTP server.|
|
|
61
|
-
|**`analyzerPort`**|`{Number}`|Default: `8888`. Port that will be used in `server` mode to start HTTP server.|
|
|
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).|
|
|
63
63
|
|**`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.|
|
|
64
64
|
|**`openAnalyzer`**|`{Boolean}`|Default: `true`. Automatically open report in default browser.|
|
|
@@ -115,7 +115,7 @@ Directory containing all generated bundles.
|
|
|
115
115
|
In `server` mode analyzer will start HTTP server to show bundle report.
|
|
116
116
|
In `static` mode single HTML file with bundle report will be generated. (default: server)
|
|
117
117
|
-h, --host <host> Host that will be used in `server` mode to start HTTP server. (default: 127.0.0.1)
|
|
118
|
-
-p, --port <n> Port that will be used in `server` mode to start HTTP server. (default: 8888)
|
|
118
|
+
-p, --port <n> Port that will be used in `server` mode to start HTTP server. Should be a number or `auto` (default: 8888)
|
|
119
119
|
-r, --report <file> Path to bundle report file that will be generated in `static` mode. (default: report.html)
|
|
120
120
|
-s, --default-sizes <type> Module sizes to show in treemap by default.
|
|
121
121
|
Possible values: stat, parsed, gzip (default: parsed)
|
|
@@ -166,22 +166,6 @@ The Chunk Context Menu can be opened by right-clicking or `Ctrl`-clicking on a s
|
|
|
166
166
|
|
|
167
167
|
<h2 align="center">Troubleshooting</h2>
|
|
168
168
|
|
|
169
|
-
### I can't see all the dependencies in a chunk
|
|
170
|
-
|
|
171
|
-
This is a known caveat when `webpack.optimize.ModuleConcatenationPlugin` is used with `Webpack 3` or `webpack-bundle-analyzer < 2.11.0`.
|
|
172
|
-
The way `ModuleConcatenationPlugin` works is that it merges multiple modules into a single one, and so that resulting module doesn't have edges anymore.
|
|
173
|
-
`Webpack 3` didn't provide any information about concatenated modules, but `Webpack 4` started including it into a `stats` files and `webpack-bundle-analyzer 2.11.0` learned to show it.
|
|
174
|
-
|
|
175
|
-
If for some reason you can't update to the latest versions try analyzing your bundle without `ModuleConcatenationPlugin`. See [issue #115](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/115) for more discussion.
|
|
176
|
-
|
|
177
|
-
If you are using `Angular CLI < 6.0.0` (which is based on `Webpack 3` and uses `ModuleConcatenationPlugin`) you can build your project using the following command:
|
|
178
|
-
```
|
|
179
|
-
ng build --stats-json --build-optimizer=false --vendor-chunk=true
|
|
180
|
-
```
|
|
181
|
-
The resulting stats.json can be found at `dist/stats.json`
|
|
182
|
-
|
|
183
|
-
*Please be aware, that this is not a reasonable build for production use, as it increases the build output size considerably.*
|
|
184
|
-
|
|
185
169
|
### I don't see `gzip` or `parsed` sizes, it only shows `stat` size
|
|
186
170
|
|
|
187
171
|
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:
|
|
@@ -4,7 +4,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
4
4
|
|
|
5
5
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
10
|
|
|
9
11
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
12
|
|
|
@@ -23,11 +25,10 @@ const Logger = require('./Logger');
|
|
|
23
25
|
const viewer = require('./viewer');
|
|
24
26
|
|
|
25
27
|
class BundleAnalyzerPlugin {
|
|
26
|
-
constructor(opts) {
|
|
28
|
+
constructor(opts = {}) {
|
|
27
29
|
this.opts = _objectSpread({
|
|
28
30
|
analyzerMode: 'server',
|
|
29
31
|
analyzerHost: '127.0.0.1',
|
|
30
|
-
analyzerPort: 8888,
|
|
31
32
|
reportFilename: 'report.html',
|
|
32
33
|
defaultSizes: 'parsed',
|
|
33
34
|
openAnalyzer: true,
|
|
@@ -38,7 +39,9 @@ class BundleAnalyzerPlugin {
|
|
|
38
39
|
logLevel: 'info',
|
|
39
40
|
// deprecated
|
|
40
41
|
startAnalyzer: true
|
|
41
|
-
}, opts
|
|
42
|
+
}, opts, {
|
|
43
|
+
analyzerPort: 'analyzerPort' in opts ? opts.analyzerPort === 'auto' ? 0 : opts.analyzerPort : 8888
|
|
44
|
+
});
|
|
42
45
|
this.server = null;
|
|
43
46
|
this.logger = new Logger(this.opts.logLevel);
|
|
44
47
|
}
|
|
@@ -49,11 +52,10 @@ class BundleAnalyzerPlugin {
|
|
|
49
52
|
const done = (stats, callback) => {
|
|
50
53
|
callback = callback || (() => {});
|
|
51
54
|
|
|
52
|
-
stats = stats.toJson(this.opts.statsOptions);
|
|
53
55
|
const actions = [];
|
|
54
56
|
|
|
55
57
|
if (this.opts.generateStatsFile) {
|
|
56
|
-
actions.push(() => this.generateStatsFile(stats));
|
|
58
|
+
actions.push(() => this.generateStatsFile(stats.toJson(this.opts.statsOptions)));
|
|
57
59
|
} // Handling deprecated `startAnalyzer` flag
|
|
58
60
|
|
|
59
61
|
|
|
@@ -62,9 +64,9 @@ class BundleAnalyzerPlugin {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
if (this.opts.analyzerMode === 'server') {
|
|
65
|
-
actions.push(() => this.startAnalyzerServer(stats));
|
|
67
|
+
actions.push(() => this.startAnalyzerServer(stats.toJson()));
|
|
66
68
|
} else if (this.opts.analyzerMode === 'static') {
|
|
67
|
-
actions.push(() => this.generateStaticReport(stats));
|
|
69
|
+
actions.push(() => this.generateStaticReport(stats.toJson()));
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
if (actions.length) {
|
|
@@ -151,7 +153,18 @@ class BundleAnalyzerPlugin {
|
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
getBundleDirFromCompiler() {
|
|
154
|
-
|
|
156
|
+
switch (this.compiler.outputFileSystem.constructor.name) {
|
|
157
|
+
case 'MemoryFileSystem':
|
|
158
|
+
return null;
|
|
159
|
+
// Detect AsyncMFS used by Nuxt 2.5 that replaces webpack's MFS during development
|
|
160
|
+
// Related: #274
|
|
161
|
+
|
|
162
|
+
case 'AsyncMFS':
|
|
163
|
+
return null;
|
|
164
|
+
|
|
165
|
+
default:
|
|
166
|
+
return this.compiler.outputPath;
|
|
167
|
+
}
|
|
155
168
|
}
|
|
156
169
|
|
|
157
170
|
}
|
package/lib/bin/analyzer.js
CHANGED
|
@@ -28,7 +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 `static`.' + 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.'), 'server').option(
|
|
31
|
+
By default a directory of stats file is used.`).option('-m, --mode <mode>', 'Analyzer mode. Should be `server` or `static`.' + 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.'), 'server').option( // Had to make `host` parameter optional in order to let `-h` flag output help message
|
|
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.', 'report.html').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);
|
|
32
34
|
let {
|
|
33
35
|
mode,
|
|
34
36
|
host,
|
|
@@ -43,8 +45,13 @@ let {
|
|
|
43
45
|
const logger = new Logger(logLevel);
|
|
44
46
|
if (!bundleStatsFile) showHelp('Provide path to Webpack Stats file as first argument');
|
|
45
47
|
if (mode !== 'server' && mode !== 'static') showHelp('Invalid mode. Should be either `server` or `static`.');
|
|
46
|
-
|
|
47
|
-
if (mode === 'server'
|
|
48
|
+
|
|
49
|
+
if (mode === 'server') {
|
|
50
|
+
if (!host) showHelp('Invalid host name');
|
|
51
|
+
port = port === 'auto' ? 0 : Number(port);
|
|
52
|
+
if (isNaN(port)) showHelp('Invalid port. Should be a number or `auto`');
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
if (!SIZES.has(defaultSizes)) showHelp(`Invalid default sizes option. Possible values are: ${[...SIZES].join(', ')}`);
|
|
49
56
|
bundleStatsFile = resolve(bundleStatsFile);
|
|
50
57
|
if (!bundleDir) bundleDir = dirname(bundleStatsFile);
|
|
@@ -80,7 +87,7 @@ if (mode === 'server') {
|
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
function showHelp(error) {
|
|
83
|
-
if (error) console.log(`\n ${magenta(error)}`);
|
|
90
|
+
if (error) console.log(`\n ${magenta(error)}\n`);
|
|
84
91
|
program.outputHelp();
|
|
85
92
|
process.exit(1);
|
|
86
93
|
}
|
|
@@ -17,7 +17,9 @@ var _utils = require("./utils");
|
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
23
|
|
|
22
24
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
25
|
|
|
@@ -9,7 +9,9 @@ var _BaseFolder = _interopRequireDefault(require("./BaseFolder"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
function
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
13
15
|
|
|
14
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
17
|
|
|
@@ -9,7 +9,9 @@ var _Module = _interopRequireDefault(require("./Module"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
function
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
13
15
|
|
|
14
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
17
|
|
package/lib/tree/Folder.js
CHANGED
|
@@ -19,7 +19,9 @@ var _utils = require("./utils");
|
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
23
25
|
|
|
24
26
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
27
|
|
package/lib/viewer.js
CHANGED
|
@@ -31,6 +31,7 @@ const Logger = require('./Logger');
|
|
|
31
31
|
const analyzer = require('./analyzer');
|
|
32
32
|
|
|
33
33
|
const projectRoot = path.resolve(__dirname, '..');
|
|
34
|
+
const assetsRoot = path.join(projectRoot, 'public');
|
|
34
35
|
module.exports = {
|
|
35
36
|
startServer,
|
|
36
37
|
generateReport,
|
|
@@ -71,11 +72,13 @@ function _startServer() {
|
|
|
71
72
|
mode: 'server',
|
|
72
73
|
|
|
73
74
|
get chartData() {
|
|
74
|
-
return
|
|
75
|
+
return chartData;
|
|
75
76
|
},
|
|
76
77
|
|
|
77
|
-
defaultSizes
|
|
78
|
-
enableWebSocket: true
|
|
78
|
+
defaultSizes,
|
|
79
|
+
enableWebSocket: true,
|
|
80
|
+
// Helpers
|
|
81
|
+
escapeJson
|
|
79
82
|
});
|
|
80
83
|
});
|
|
81
84
|
const server = http.createServer(app);
|
|
@@ -145,10 +148,12 @@ function _generateReport() {
|
|
|
145
148
|
yield new Promise((resolve, reject) => {
|
|
146
149
|
ejs.renderFile(`${projectRoot}/views/viewer.ejs`, {
|
|
147
150
|
mode: 'static',
|
|
148
|
-
chartData
|
|
151
|
+
chartData,
|
|
152
|
+
defaultSizes,
|
|
153
|
+
enableWebSocket: false,
|
|
154
|
+
// Helpers
|
|
149
155
|
assetContent: getAssetContent,
|
|
150
|
-
|
|
151
|
-
enableWebSocket: false
|
|
156
|
+
escapeJson
|
|
152
157
|
}, (err, reportHtml) => {
|
|
153
158
|
try {
|
|
154
159
|
if (err) {
|
|
@@ -177,7 +182,21 @@ function _generateReport() {
|
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
function getAssetContent(filename) {
|
|
180
|
-
|
|
185
|
+
const assetPath = path.join(assetsRoot, filename);
|
|
186
|
+
|
|
187
|
+
if (!assetPath.startsWith(assetsRoot)) {
|
|
188
|
+
throw new Error(`"${filename}" is outside of the assets root`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return fs.readFileSync(assetPath, 'utf8');
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Escapes `<` characters in JSON to safely use it in `<script>` tag.
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
function escapeJson(json) {
|
|
199
|
+
return JSON.stringify(json).replace(/</gu, '\\u003c');
|
|
181
200
|
}
|
|
182
201
|
|
|
183
202
|
function getChartData(analyzerOpts, ...args) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-bundle-analyzer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
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",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"express": "^4.16.3",
|
|
43
43
|
"filesize": "^3.6.1",
|
|
44
44
|
"gzip-size": "^5.0.0",
|
|
45
|
-
"lodash": "^4.17.
|
|
45
|
+
"lodash": "^4.17.15",
|
|
46
46
|
"mkdirp": "^0.5.1",
|
|
47
47
|
"opener": "^1.5.1",
|
|
48
48
|
"ws": "^6.0.0"
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@babel/preset-react": "7.0.0",
|
|
58
58
|
"@babel/register": "7.4.0",
|
|
59
59
|
"@babel/runtime": "7.4.3",
|
|
60
|
+
"autoprefixer": "9.5.1",
|
|
60
61
|
"babel-eslint": "10.0.1",
|
|
61
62
|
"babel-loader": "8.0.5",
|
|
62
63
|
"babel-plugin-lodash": "3.3.4",
|