angular: lvy:Library build by angular-cli can not tree shaking in apps
🐞 bug report
Affected Package
Is this a regression?
it can not work in ng8 also, but i try to ask if it can work in ng9 or not
Description
A library build by angular-cli, improt a module or declare a component of the library into a app, then build the app with aot, the whole library code gets into bundle, the tree shaking did not work
🔬 Minimal Reproduction
https://stackblitz.com/edit/angular-srduuh
🔥 Exception or Error
In the demo i use the library jigsaw(https://github.com/rdkmaster/jigsaw) which build by angular-cli
and i import the module JigsawButtonModule
which just has the component JigsawButton
into AppModule
if you build the app with this environment,you will get the whole jigsaw code in vender.js
🌍 Your Environment
Angular CLI: 9.0.0-rc.7 Node: 10.18.0 OS: win32 x64
Angular: 9.0.0-rc.7 … animations, cli, common, compiler, compiler-cli, core, forms … language-service, platform-browser, platform-browser-dynamic … router Ivy Workspace: Yes
Package Version
@angular-devkit/architect 0.900.0-rc.7 @angular-devkit/build-angular 0.900.0-rc.7 @angular-devkit/build-optimizer 0.900.0-rc.7 @angular-devkit/build-webpack 0.900.0-rc.7 @angular-devkit/core 9.0.0-rc.7 @angular-devkit/schematics 9.0.0-rc.7 @ngtools/webpack 9.0.0-rc.7 @schematics/angular 9.0.0-rc.7 @schematics/update 0.900.0-rc.7 rxjs 6.5.3 typescript 3.6.4 webpack 4.41.2
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (9 by maintainers)
Commits related to this issue
- fix(@angular-devkit/build-optimizer): wrap classes which contain empty statements (#16538) NGCC currently produces empty statments which breaks class wrapping. Closes #16509 — committed to angular/angular-cli by alan-agius4 4 years ago
- fix(@angular-devkit/build-optimizer): wrap classes which contain empty statements (#16538) NGCC currently produces empty statments which breaks class wrapping. Closes #16509 — committed to angular/angular-cli by alan-agius4 4 years ago
- fix(ngcc): insert definitions after statement If a class was defined as a class expression in a variable declaration, the definitions were being inserted before the statment's final semi-colon. Now ... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): insert definitions after statement (#34677) If a class was defined as a class expression in a variable declaration, the definitions were being inserted before the statment's final semi-col... — committed to angular/angular by petebacondarwin 4 years ago
To elucidate, in ES2015 formats, where the class is defined via a
let
statement, ngcc is incorrectly taking the class expression, rather than the variable declaration statement as the node to use for inserting definitions. This should be a simple fix inEsmRenderingFormatter.addDefinitions()
.--aot
alone will not do any treeshaking or dead code elimination, hence the entire library will be retained.The flags which are associated with tree-shaking and dead-code elimination are
--optimization
and--build-optimizer
which are enabled by default under the production configuration.To disable mangling you can use the
NG_BUILD_MANGLE
environment variable: