Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to analyze gzipped bundles #379

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

xitter
Copy link

@xitter xitter commented Aug 31, 2020

Feature request: #377

This would add functionality to generate stats for .gz and .br, i.e. compressed assets.

@xitter xitter changed the title Add support to analyze gzipped bundles feat: add support to analyze gzipped bundles Aug 31, 2020
README.md Outdated
@@ -68,6 +68,7 @@ new BundleAnalyzerPlugin(options?: object)
|**`statsOptions`**|`null` or `{Object}`|Default: `null`. Options for `stats.toJson()` method. For example you can exclude sources of your modules from stats file with `source: false` option. [See more options here](https://webpack.js.org/configuration/stats/). |
|**`excludeAssets`**|`{null\|pattern\|pattern[]}` where `pattern` equals to `{String\|RegExp\|function}`|Default: `null`. Patterns that will be used to match against asset names to exclude them from the report. If pattern is a string it will be converted to RegExp via `new RegExp(str)`. If pattern is a function it should have the following signature `(assetName: string) => boolean` and should return `true` to *exclude* matching asset. If multiple patterns are provided asset should match at least one of them to be excluded. |
|**`logLevel`**|One of: `info`, `warn`, `error`, `silent`|Default: `info`. Used to control how much details the plugin outputs.|
|**`decompressExtenstion`**|`null` or `{Object}`|Default: `null`. Used to show stats for a compressed file, object has compressed file's extension as key and it's value is decompression algorithm of [zlib](https://nodejs.org/api/zlib.html) to use, like: `{ gz: { algorithm: 'unzipSync' } }`|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this option - decompression should be transparent to the end-user. It should just work without any configuration.

Copy link
Author

@xitter xitter Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too agree on this, but then should it be basis extension itself, i.e. detect for gz/br and apply respective decompression?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@th0r does the above comment look good?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. We can think about customizable extensions if someone will raise an issue about it.

@@ -16,7 +21,7 @@ describe('parseBundle', function () {
.forEach(bundleName => {
it(`should parse ${_.lowerCase(bundleName)}`, function () {
const bundleFile = `${BUNDLES_DIR}/${bundleName}.js`;
const bundle = parseBundle(bundleFile);
const bundle = parseBundle(bundleFile, {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options parameter should be optional.

const bundleFile = `${BUNDLES_DIR}/validBundleWithArrowFunction.js`;
const compressedBundleFile = `${bundleFile}.${extension}`;
const expectedModules = JSON.parse(fs.readFileSync(`${BUNDLES_DIR}/validBundleWithArrowFunction.modules.json`));
if (!zlib[algorithm]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this condition - it swallows valid error and we won't notice it.

Copy link
Author

@xitter xitter Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For brotli, node version needs to be >= v11.7.0. Thus I put it to pass ci-checks which run on node 8. How do you suggest handling it?

Copy link
Collaborator

@th0r th0r Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For brotli, node version needs to be >= v11.7.0

We need to mention it in the docs and properly handle in the code.

Copy link
Collaborator

@th0r th0r Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you suggest handling it?

Check in tests, whether current version of Node supports it and expect successful decoding in one case and throwing of expected error in the other.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to mention it in the docs and properly handle in the code.

Brotli compression works for version >= v11.7.0, so it is kind of an already set expectation for brotli assets. Would you prefer it including in docs anyway?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Maybe compression is done with some external tool instead of Node.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants