-
Notifications
You must be signed in to change notification settings - Fork 12k
@ngtools/webpack - enable sourceMap generates different build #14617
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
Comments
This seems unintended. I'm not sure why that would change... if you're interested in looking at this bug, I expect https://github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/angular_compiler_plugin.ts is the right place. |
I'm investigating this problem but I am a bit confused by your report and repro.
You have both a static import to
and a dynamic import:
You expect the direct import to be removed because In In So at this point I can see that setting source-maps to false prevents a lazy chunk from being generated. Yes this looks like a weird problem. But it doesn't impact total bundle size. You mention that this bug increases your build size by ~100kb but I am not seeing that here. What I see instead is that the contents of a lazy chunk were inlined in another chunk. So same total size, but different distribution. What also confuses me is that you say that you have to disable sourcemaps. But disabling sourcemaps is what causes the inlining. According to this repo, I expected you to have to enable sourcemaps in order to actually have a lazy loaded chunk. I'll continue looking into why there's a difference of behaviour regardless. |
The reason setting sourcemap makes a difference is related to Build Optimizer. When sourcemaps are not used, we run build optimizer in a less resource-intensive mode. This makes a difference because it uses TypeScript, and TypeScript in its "full" mode removes unused imports. But on the less resource-intensive mode, it doesn't. That's part one of the mystery. Part two of the mystery is why the unused imports were not removed during the original TypeScript compilation via We have a code transformation that removes unused angular decorators: https://github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/transformers/remove_decorators.ts This is the original compiled
And this is how it looks with the transformation:
The end result is that |
#16085 should fix this. What happened was this:
Now we correctly identify type references as not being a usage for an import, for eliding purposes. |
nice, thank you :)
That build size increase was based on our production build - not the reproduction. I guess I should have had added some more files so the alteration in the build was more obvious. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
@ngtools/webpack
produces different javascript output if you toggle the sourceMap setting. With source maps enabled, the compiler seems to include imports, that shouldn't be there.Angular: 8.0.0 (but issue is present in 7.2.x as well)
Reproduction: https://github.com/sod/issue-ngtools-14617
Compare both dist-* folders. The only difference in the build is the
--source-map
flag. In one build the chunkbig-dependency
is missing and was inlined by webpack.You can try to build it yourself with either one:
If you watch the output with
--source-map
of the ngtools/webpack loader in https://github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/loader.ts#L104, I see for the file https://github.com/sod/issue-ngtools-14617/blob/master/src/app/lorem/lorem.service.ts this output:BigDependencyOptions
is an Interface and only used as a type, that import should not be visible in javascript. If you throw the source into typescriptlang, you see that tsc wouldn't include that import as well.We use an error reporting tool where we can upload the source maps to get better reports. But this behavior increases our build by ~100kb so we compile without source maps right now.
The text was updated successfully, but these errors were encountered: