webpack-bundle-analyzer 4.4.1 → 4.6.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,28 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
12
12
 
13
13
  ## UNRELEASED
14
14
 
15
+ ## 4.6.0
16
+
17
+ * **New Feature**
18
+ * Support outputting different URL in server mode ([#520](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/520) by [@southorange1228](https://github.com/southorange1228))
19
+ * Use deterministic chunk colors (#[501](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/501) by [@CreativeTechGuy](https://github.com/CreativeTechGuy))
20
+
21
+ ## 4.5.0
22
+
23
+ * **Improvement**
24
+ * Stop publishing src folder to npm ([#478](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/478) by [@wood1986](https://github.com/wood1986))
25
+
26
+ * **Internal**
27
+ * Update some dependencies ([#448](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/448))
28
+ * Replace nightmare with Puppeteer ([#469](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/469) by [@valscion](https://github.com/valscion))
29
+ * Replace Mocha with Jest ([#470](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/470) by [@valscion](https://github.com/valscion))
30
+
31
+ ## 4.4.2
32
+
33
+ * **Bug Fix**
34
+ * Fix failure with `compiler.outputFileSystem.constructor` being `undefined` ([#447](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/447) by [@kedarv](https://github.com/kedarv) and [@alexander-akait](https://github.com/alexander-akait))
35
+ * **NOTE:** This fix doesn't have added test coverage so the fix might break in future versions unless test coverage is added later.
36
+
15
37
  ## 4.4.1
16
38
 
17
39
  * **Bug Fix**
package/README.md CHANGED
@@ -59,6 +59,7 @@ new BundleAnalyzerPlugin(options?: object)
59
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
+ |**`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
63
  |**`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
64
  |**`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.|
64
65
  |**`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.|
@@ -173,8 +174,8 @@ The Chunk Context Menu can be opened by right-clicking or `Ctrl`-clicking on a s
173
174
 
174
175
  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:
175
176
  ```
176
- Couldn't parse bundle asset "your_bundle_name.bundle.js".
177
- Analyzer will use module sizes from stats file.
177
+ Error parsing bundle asset "your_bundle_name.bundle.js": no such file
178
+ No bundles were parsed. Analyzer will show only original module sizes from stats file.
178
179
  ```
179
180
  To get more information about it you can read [issue #147](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/147).
180
181
 
@@ -34,6 +34,7 @@ class BundleAnalyzerPlugin {
34
34
  logLevel: 'info',
35
35
  // deprecated
36
36
  startAnalyzer: true,
37
+ analyzerUrl: utils.defaultAnalyzerUrl,
37
38
  ...opts,
38
39
  analyzerPort: 'analyzerPort' in opts ? opts.analyzerPort === 'auto' ? 0 : opts.analyzerPort : 8888
39
40
  };
@@ -114,7 +115,8 @@ class BundleAnalyzerPlugin {
114
115
  bundleDir: this.getBundleDirFromCompiler(),
115
116
  logger: this.logger,
116
117
  defaultSizes: this.opts.defaultSizes,
117
- excludeAssets: this.opts.excludeAssets
118
+ excludeAssets: this.opts.excludeAssets,
119
+ analyzerUrl: this.opts.analyzerUrl
118
120
  });
119
121
  }
120
122
  }
@@ -141,6 +143,10 @@ class BundleAnalyzerPlugin {
141
143
  }
142
144
 
143
145
  getBundleDirFromCompiler() {
146
+ if (typeof this.compiler.outputFileSystem.constructor === 'undefined') {
147
+ return this.compiler.outputPath;
148
+ }
149
+
144
150
  switch (this.compiler.outputFileSystem.constructor.name) {
145
151
  case 'MemoryFileSystem':
146
152
  return null;
@@ -24,13 +24,14 @@ const SIZES = new Set(['stat', 'parsed', 'gzip']);
24
24
  const program = commander.version(require('../../package.json').version).usage(`<bundleStatsFile> [bundleDir] [options]
25
25
 
26
26
  Arguments:
27
-
27
+
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
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
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('-t, --title <title>', 'String to use in title element of html report.').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
+ let [bundleStatsFile, bundleDir] = program.args;
34
35
  let {
35
36
  mode,
36
37
  host,
@@ -40,9 +41,8 @@ let {
40
41
  defaultSizes,
41
42
  logLevel,
42
43
  open: openBrowser,
43
- exclude: excludeAssets,
44
- args: [bundleStatsFile, bundleDir]
45
- } = program;
44
+ exclude: excludeAssets
45
+ } = program.opts();
46
46
  const logger = new Logger(logLevel);
47
47
 
48
48
  if (typeof reportTitle === 'undefined') {
package/lib/utils.js CHANGED
@@ -53,6 +53,14 @@ exports.defaultTitle = function () {
53
53
  const currentTime = `${day} ${month} ${year} at ${hour}:${minute}`;
54
54
  return `${process.env.npm_package_name || 'Webpack Bundle Analyzer'} [${currentTime}]`;
55
55
  };
56
+
57
+ exports.defaultAnalyzerUrl = function (options) {
58
+ const {
59
+ listenHost,
60
+ boundAddress
61
+ } = options;
62
+ return `http://${listenHost}:${boundAddress.port}`;
63
+ };
56
64
  /**
57
65
  * Calls opener on a URI, but silently try / catches it.
58
66
  */
package/lib/viewer.js CHANGED
@@ -55,7 +55,8 @@ async function startServer(bundleStats, opts) {
55
55
  logger = new Logger(),
56
56
  defaultSizes = 'parsed',
57
57
  excludeAssets = null,
58
- reportTitle
58
+ reportTitle,
59
+ analyzerUrl
59
60
  } = opts || {};
60
61
  const analyzerOpts = {
61
62
  logger,
@@ -87,7 +88,11 @@ async function startServer(bundleStats, opts) {
87
88
  await new Promise(resolve => {
88
89
  server.listen(port, host, () => {
89
90
  resolve();
90
- const url = `http://${host}:${server.address().port}`;
91
+ const url = analyzerUrl({
92
+ listenPort: port,
93
+ listenHost: host,
94
+ boundAddress: server.address()
95
+ });
91
96
  logger.info(`${bold('Webpack Bundle Analyzer')} is started at ${bold(url)}\n` + `Use ${bold('Ctrl+C')} to close it`);
92
97
 
93
98
  if (openBrowser) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-bundle-analyzer",
3
- "version": "4.4.1",
3
+ "version": "4.6.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",
@@ -24,19 +24,18 @@
24
24
  "npm-publish": "npm run lint && npm run build && npm test && npm publish",
25
25
  "lint": "eslint --ext js,jsx .",
26
26
  "install-test-webpack-versions": "./bin/install-test-webpack-versions.sh",
27
- "test": "npm run install-test-webpack-versions && mocha --exit --require @babel/register",
28
- "test-dev": "npm run install-test-webpack-versions && mocha --watch --watch-ignore test/output --require @babel/register"
27
+ "test": "npm run install-test-webpack-versions && jest --runInBand",
28
+ "test-dev": "npm run install-test-webpack-versions && jest --watch --runInBand"
29
29
  },
30
30
  "files": [
31
31
  "public",
32
- "lib",
33
- "src"
32
+ "lib"
34
33
  ],
35
34
  "dependencies": {
36
35
  "acorn": "^8.0.4",
37
36
  "acorn-walk": "^8.0.0",
38
37
  "chalk": "^4.1.0",
39
- "commander": "^6.2.0",
38
+ "commander": "^7.2.0",
40
39
  "gzip-size": "^6.0.0",
41
40
  "lodash": "^4.17.20",
42
41
  "opener": "^1.5.2",
@@ -44,50 +43,48 @@
44
43
  "ws": "^7.3.1"
45
44
  },
46
45
  "devDependencies": {
47
- "@babel/core": "7.12.3",
48
- "@babel/plugin-proposal-class-properties": "7.12.1",
49
- "@babel/plugin-proposal-decorators": "7.12.1",
50
- "@babel/plugin-transform-runtime": "7.12.1",
51
- "@babel/preset-env": "7.12.1",
52
- "@babel/preset-react": "7.12.5",
53
- "@babel/register": "7.12.1",
54
- "@babel/runtime": "7.12.5",
46
+ "@babel/core": "7.14.3",
47
+ "@babel/plugin-proposal-class-properties": "7.13.0",
48
+ "@babel/plugin-proposal-decorators": "7.14.2",
49
+ "@babel/plugin-transform-runtime": "7.14.3",
50
+ "@babel/preset-env": "7.14.2",
51
+ "@babel/preset-react": "7.13.13",
52
+ "@babel/runtime": "7.14.0",
55
53
  "@carrotsearch/foamtree": "3.5.0",
56
- "autoprefixer": "10.0.1",
54
+ "autoprefixer": "10.2.5",
57
55
  "babel-eslint": "10.1.0",
58
- "babel-loader": "8.1.0",
56
+ "babel-loader": "8.2.2",
59
57
  "babel-plugin-lodash": "3.3.4",
60
- "chai": "4.2.0",
58
+ "chai": "4.3.4",
61
59
  "chai-subset": "1.6.0",
62
- "classnames": "2.2.6",
63
- "core-js": "3.6.5",
64
- "css-loader": "5.0.1",
65
- "cssnano": "4.1.10",
60
+ "classnames": "2.3.1",
61
+ "core-js": "3.12.1",
62
+ "css-loader": "5.2.5",
63
+ "cssnano": "5.0.4",
66
64
  "del": "6.0.0",
67
65
  "eslint": "5.16.0",
68
66
  "eslint-config-th0r": "2.0.0",
69
67
  "eslint-config-th0r-react": "2.0.1",
70
- "eslint-plugin-react": "7.21.5",
71
- "exports-loader": "1.1.1",
72
- "filesize": "^6.1.0",
73
- "globby": "11.0.1",
68
+ "eslint-plugin-react": "7.23.2",
69
+ "filesize": "^6.3.0",
70
+ "globby": "11.0.3",
74
71
  "gulp": "4.0.2",
75
72
  "gulp-babel": "8.0.0",
73
+ "jest": "27.2.2",
76
74
  "mobx": "5.15.7",
77
75
  "mobx-react": "6.3.1",
78
- "mocha": "8.2.1",
79
- "nightmare": "3.0.2",
80
- "postcss": "8.1.6",
76
+ "postcss": "8.3.0",
81
77
  "postcss-icss-values": "2.0.2",
82
- "postcss-loader": "4.0.4",
83
- "preact": "10.5.5",
78
+ "postcss-loader": "5.3.0",
79
+ "preact": "10.5.13",
80
+ "puppeteer": "10.4.0",
84
81
  "stream-combiner2": "1.1.1",
85
82
  "style-loader": "2.0.0",
86
- "terser-webpack-plugin": "5.0.3",
83
+ "terser-webpack-plugin": "5.1.2",
87
84
  "url-loader": "4.1.1",
88
- "webpack": "5.4.0",
85
+ "webpack": "5.37.1",
89
86
  "webpack-cli": "3.3.12",
90
- "webpack-dev-server": "3.11.0"
87
+ "webpack-dev-server": "3.11.2"
91
88
  },
92
89
  "keywords": [
93
90
  "webpack",