You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
webpack-bundle-analyzer not working correctly with the latest cli 1.3.0-beta.1 #7057
I understand this happens, but I don't think this is an issue in Angular CLI. We just pass on the stats json option into webpack, and then webpack-bundle-analyzer is used to analyse it. The CLI doesn't do anything at all with that file.
My guess would be an incompatibility with scope hoisting.
Yes, this is very likely to be the issue with webpack-bundle-analyzer. As it happens, webpack-bundle-analyzer is not yet compatible with webpack's scope hoisting.
We're figuring out a solution for this, but for now, drilling deeper into the bundle isn't possible.
You could try to view the "stat" size, as it doesn't rely on parsing the generated bundle (where, due to scope hoisting, we've lost the details of module boundaries)
@ShadowManu I think there's something odd with the setup reported in webpack/webpack-bundle-analyzer#106, since it does mention CLI 1.2.6 but also Webpack 3.4.1, but CLI 1.2.6 is limited to webpack 2.x.
@valscion heya, thanks for chiming in! If there something we can do on Angular CLI to help please let me know.
@filipesilva one possibility would be to configure the builds to not use scope hoisting when you want to analyze the bundle contents with webpack-bundle-analyzer. This way the plugin would be able to show you the sizes of each modules separately.
I'm not sure if we're able to even figure out the missing information after the scope hoisting, but I haven't yet looked into it that much.
Hmm, resulting stats file has very strange structure. @filipesilva Could you provide some insides about what have been changed in webpack configuration in ng-cli 1.3.0-rc.3?
The fact is from @angular/cli@1.2.6 to @angular/cli@1.3.0-rc.3, the webpack version is upgraded from ~2.4.0 to ~3.4.0. There are breaking changes inside webpack which affect @angualr/cli.
As @valscion said, a temporary solution is to provide a flag in @angular/cli to turn off webpack.optimize.ModuleConcatenationPlugin() at here
Yeah th0r knows webpack-bundle-analyzer better than me, and I'm thrilled to hear that ModuleConcatenationPlugin works. So there might be something else that the @angular/cli is doing.
@e-cloud The problem is in the stats.json structure. Normally it is something like this:
{// ..."chunks": [// chunks info WITHOUT modules],"modules": [// list of ALL modules from ALL chunks]// ...}
But new ng-cli generates stats file with the following structure:
{// ..."chunks": [// chunks info WITH modules.// each chunk object has it's own "modules" property with all modules it contains]// ...and no top-level "modules" field}
So there is no top-level modules field, but all of them are spread across chunk objects.
The webpack stats output is highly configurable and its content can vary greatly depending on webpack command line options or programmatic usage. In this case, the verbose preset is used which seems to purposely not include the module list that the analyzer requires. (code ref)
To that end, is there a reason that the analyzer requires the presence of the top-level modules list? If the chunk modules are present, the analyzer seems to be doing extra work (code ref) filtering the entire modules list to find the modules used per asset. Also, since there is technically no guarantee that either of the module lists are present, it may be prudent to use chunk modules if available (more efficient), then the top-level modules if not, and finally display an error/warning if neither is found.
Regardless, I'll put together a PR that will make the Angular CLI use the same stat output options for the file that the current default --json webpack CLI option uses.
@clydin The thing is it's the first time I see that modules are located in chunk objects.
Do you use some plugin that modifies default stats structure or it can be achieved by just changing stats options?
A direct webpack function call is used to obtain the stats object. It supports several presets as well as a fine-grained object-based option argument. Oddly, the default includes both the modules and chunk modules lists; but verbose only includes chunk modules.
Here is the relevant code for the fine-grained options (and their defaults): https://github.com/webpack/webpack/blob/master/lib/Stats.js#L101
Big thanks to @clydin for the investigative work here.
Breaking webpack-bundle-analyzer was indeed a consequence of #6989 where we started using stats.toJson('verbose') instead of just stats.toJson() , subsequently fixed by #7259.
After some additional research, the CLI didn't actually break the functionality. Webpack 3 changed the verbose preset to not include the top level module list.
Reacted by Michael Sanford
angular-automatic-lock-bot commented on Sep 7, 2019
Activity
deebloo commentedon Jul 20, 2017
I can confirm the issue. Haven't been able to track down the problem though
clydin commentedon Jul 20, 2017
My guess would be an incompatibility with scope hoisting.
If the contents of the bundles is the goal, you can turn on sourcemaps and use sourcemap explorer.
kuncevic commentedon Jul 23, 2017
Just tested with rc.0 and still an issue.
filipesilva commentedon Jul 28, 2017
I understand this happens, but I don't think this is an issue in Angular CLI. We just pass on the stats json option into
webpack, and thenwebpack-bundle-analyzeris used to analyse it. The CLI doesn't do anything at all with that file.Have you tried opening an issue in https://github.com/th0r/webpack-bundle-analyzer or https://github.com/webpack/webpack instead? If it's a matter of updating our version of either I'm happy to do so.
ShadowManu commentedon Jul 29, 2017
There is an opened issue reporting for CLI 1.2.6, so probably not related to changes on 1.3.
valscion commentedon Jul 29, 2017
Yes, this is very likely to be the issue with
webpack-bundle-analyzer. As it happens,webpack-bundle-analyzeris not yet compatible with webpack's scope hoisting.We're figuring out a solution for this, but for now, drilling deeper into the bundle isn't possible.
You could try to view the "stat" size, as it doesn't rely on parsing the generated bundle (where, due to scope hoisting, we've lost the details of module boundaries)
filipesilva commentedon Jul 31, 2017
@ShadowManu I think there's something odd with the setup reported in webpack/webpack-bundle-analyzer#106, since it does mention CLI 1.2.6 but also Webpack 3.4.1, but CLI 1.2.6 is limited to webpack 2.x.
@valscion heya, thanks for chiming in! If there something we can do on Angular CLI to help please let me know.
chriszrc commentedon Jul 31, 2017
Even using sourcemaps, using the latest cli (1.3.0.rc3), all information about the vendor libs is gone
filipesilva commentedon Jul 31, 2017
The sourcemaps bit is a bug with the
--build-optimizerflag and being tracked in #7093.valscion commentedon Aug 1, 2017
@filipesilva one possibility would be to configure the builds to not use scope hoisting when you want to analyze the bundle contents with
webpack-bundle-analyzer. This way the plugin would be able to show you the sizes of each modules separately.I'm not sure if we're able to even figure out the missing information after the scope hoisting, but I haven't yet looked into it that much.
th0r commentedon Aug 2, 2017
Hmm, resulting stats file has very strange structure.
@filipesilva Could you provide some insides about what have been changed in webpack configuration in ng-cli 1.3.0-rc.3?
e-cloud commentedon Aug 3, 2017
The fact is from
@angular/cli@1.2.6to@angular/cli@1.3.0-rc.3, the webpack version is upgraded from~2.4.0to~3.4.0. There are breaking changes inside webpack which affect@angualr/cli.As @valscion said, a temporary solution is to provide a flag in
@angular/clito turn offwebpack.optimize.ModuleConcatenationPlugin()at heree-cloud commentedon Aug 3, 2017
sorry, simple comment out the plugin doesn't work. There are more things to reconfig.
e-cloud commentedon Aug 3, 2017
Even without prod mode, like
ng build --no-progress --stats-json, webpack-bundle-analyzer doesn't make it out.th0r commentedon Aug 3, 2017
@e-cloud I use Webpack 3.4 with ModuleConcatenationPlugin in one of my projects and analyzer works fine in my case.
I think it's something else.
e-cloud commentedon Aug 3, 2017
@th0r, do you use @angular/cli? If not, it sounds may be cli has its own problem too.
th0r commentedon Aug 3, 2017
@e-cloud No, I don't.
valscion commentedon Aug 3, 2017
Yeah th0r knows
webpack-bundle-analyzerbetter than me, and I'm thrilled to hear thatModuleConcatenationPluginworks. So there might be something else that the @angular/cli is doing.th0r commentedon Aug 3, 2017
@e-cloud The problem is in the
stats.jsonstructure. Normally it is something like this:But new
ng-cligenerates stats file with the following structure:So there is no top-level
modulesfield, but all of them are spread acrosschunkobjects.clydin commentedon Aug 3, 2017
The webpack stats output is highly configurable and its content can vary greatly depending on
webpackcommand line options or programmatic usage. In this case, theverbosepreset is used which seems to purposely not include the module list that the analyzer requires. (code ref)To that end, is there a reason that the analyzer requires the presence of the top-level modules list? If the chunk modules are present, the analyzer seems to be doing extra work (code ref) filtering the entire modules list to find the modules used per asset. Also, since there is technically no guarantee that either of the module lists are present, it may be prudent to use chunk modules if available (more efficient), then the top-level modules if not, and finally display an error/warning if neither is found.
Regardless, I'll put together a PR that will make the Angular CLI use the same stat output options for the file that the current default
--jsonwebpack CLI option uses.th0r commentedon Aug 3, 2017
@clydin The thing is it's the first time I see that
modulesare located inchunkobjects.Do you use some plugin that modifies default stats structure or it can be achieved by just changing stats options?
clydin commentedon Aug 3, 2017
A direct webpack function call is used to obtain the stats object. It supports several presets as well as a fine-grained object-based option argument. Oddly, the default includes both the modules and chunk modules lists; but verbose only includes chunk modules.
Here is the relevant code for the fine-grained options (and their defaults): https://github.com/webpack/webpack/blob/master/lib/Stats.js#L101
filipesilva commentedon Aug 4, 2017
Big thanks to @clydin for the investigative work here.
Breaking
webpack-bundle-analyzerwas indeed a consequence of #6989 where we started usingstats.toJson('verbose')instead of juststats.toJson(), subsequently fixed by #7259.clydin commentedon Aug 4, 2017
After some additional research, the CLI didn't actually break the functionality. Webpack 3 changed the verbose preset to not include the top level module list.
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.