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

Allowing capability to parse bundles that have child assets generated, along with main asset #376

Merged
merged 1 commit into from
Aug 27, 2020

Conversation

masterkidan
Copy link
Contributor

This essentially attempts to solve #150, when worker-loader is used it generates bundles with the following compilation stat

1 main asset
Children Assets
image

The main chunk that is emitted bundle.worker.js, doesn't have any children associated with, the webpack compiler instead spits out the dependencies as part of stats.children.assets.

This PR attempts to solve the above by traversing the children assets and constructing trees for them as well.

@jsf-clabot
Copy link

jsf-clabot commented Aug 19, 2020

CLA assistant check
All committers have signed the CLA.

@masterkidan
Copy link
Contributor Author

@jsf-clabot rerun

@valscion
Copy link
Member

Seems like the first commit in this PR has an email address associated with it that is not associated with your GitHub account. You will need to fix that e.g. with interactive rebasing and resetting the commit author details, and then force pushing your changed branch here to fix CLA check.

@masterkidan
Copy link
Contributor Author

@valscion : I've fixed the cla issues now, please review the changeset and lmk if it looks ok.

@valscion
Copy link
Member

I do appreciate the tests you added. I'm unfortunately not so knowledgeable in the specific codepath you're changing, so I'll defer to @th0r for reviewing.

Is there something in particular in this diff that you could do differently @masterkidan or that you think could cause issues in the future? Is there something that you think could cause maintenance burden?

@masterkidan
Copy link
Contributor Author

Nothing springs to my mind here, let’s wait for @th0r to review.

@masterkidan
Copy link
Contributor Author

@th0r: A gentle ping for a review, I would like to get this in so that I can unblock some local debugging issues am having with large bundle sizes for workers.

@valscion
Copy link
Member

Oh well, we can always fix any problems that arise if this code breaks. We also have a test case for this, and the code seems quite OK to me ☺️.

Let's move ahead with this one. Thank you for the contribution, @masterkidan ☺️

@valscion valscion merged commit 2ea638f into webpack-contrib:master Aug 27, 2020
@masterkidan
Copy link
Contributor Author

Thanks @valscion: Is it possible to get a patch/minor release with the above changes so that I can consume the updates? Will it get generated automatically?

@valscion
Copy link
Member

Yeah I was in the progress of releasing a new version yesterday but then my time ran out. It's been a while since there was an update, so I'm looking at if I can also bump some dependencies in a backwards compatible manner before I release a new version.

I'll try to remember to comment here when we release a new version. I can't promise any given timeline, as it depends on when I have a nice time slot to do the update.

@dabbott
Copy link
Contributor

dabbott commented Aug 29, 2020

I was having some large worker bundle issues, so I ended up pulling master and trying this out.

I ran into an issue where an error is thrown because getChildAssetBundles returns undefined. I think it's potentially due to the HtmlWebpackPlugin in my project, but I really don't know the internals of webpack or bundle analyzer at all so I'm not sure. I found that for my asset names, e.g. 9.typescript-worker-bundle.js, the only chunkByAssetName keys that existed were [ 'HtmlWebpackPlugin_0' , 'main', 'main' ]. That's as far as I got in debugging, but I'm afraid I don't have time at the moment to dig deeper.

Here's a quick fix if you want one: #378

With that, this works great and I'm able to see worker bundle stats now 😃

@valscion
Copy link
Member

Thanks for testing these changes, @dabbott!

ctavan added a commit to ctavan/webpack-bundle-analyzer that referenced this pull request Nov 11, 2020
When trying to analyze a stats.json for a webpack bundle generated off
of an array webpack.config.json webpack-bundle-analyzer was throwing:

Could't analyze webpack bundle:
TypeError: Cannot read property 'assets' of undefined

This bug was probably introduced in
webpack-contrib#376

Example webpack config to generate a stats.json file that causes the
crash:

```js
function getConfig({ config }) {
  return {
    mode: 'production',
    entry: './src/index.js',
    performance: {
      hints: 'warning',
    },
    optimization: {
      minimize: true,
    },
    output: {
      filename: `${config}-[name].js`,
      chunkFilename: `${config}-chunk-[name].js`,
      path: `${__dirname}/`,
    },
  };
}

module.exports = [{ config: 'config-1' }, { config: 'config-2' }].map(getConfig);
```
ctavan added a commit to ctavan/webpack-bundle-analyzer that referenced this pull request Nov 11, 2020
When trying to analyze a stats.json for a webpack bundle generated off
of an array webpack.config.json webpack-bundle-analyzer was throwing:

Could't analyze webpack bundle:
TypeError: Cannot read property 'assets' of undefined

This bug was probably introduced in
webpack-contrib#376

Example webpack config to generate a stats.json file that causes the
crash:

```js
function getConfig({ config }) {
  return {
    mode: 'production',
    entry: './src/index.js',
    performance: {
      hints: 'warning',
    },
    optimization: {
      minimize: true,
    },
    output: {
      filename: `${config}-[name].js`,
      chunkFilename: `${config}-chunk-[name].js`,
      path: `${__dirname}/`,
    },
  };
}

module.exports = [{ config: 'config-1' }, { config: 'config-2' }].map(getConfig);
```
ctavan added a commit to ctavan/webpack-bundle-analyzer that referenced this pull request Nov 11, 2020
When trying to analyze a stats.json for a webpack bundle generated off
of an array webpack.config.json webpack-bundle-analyzer was throwing:

Could't analyze webpack bundle:
TypeError: Cannot read property 'assets' of undefined

This bug was probably introduced in
webpack-contrib#376

Example webpack config to generate a stats.json file that causes the
crash:

```js
function getConfig({ config }) {
  return {
    mode: 'production',
    entry: './src/index.js',
    performance: {
      hints: 'warning',
    },
    optimization: {
      minimize: true,
    },
    output: {
      filename: `${config}-[name].js`,
      chunkFilename: `${config}-chunk-[name].js`,
      path: `${__dirname}/`,
    },
  };
}

module.exports = [{ config: 'config-1' }, { config: 'config-2' }].map(getConfig);
```
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.

4 participants