question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lvy:Library build by angular-cli can not tree shaking in apps

See original GitHub issue

🐞 bug report

Affected Package

@angular/cli

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

image

and i import the module JigsawButtonModule which just has the component JigsawButton into AppModule

image

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, Jan 6, 2020

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 in EsmRenderingFormatter.addDefinitions().

1reaction
alan-agius4commented, Dec 30, 2019

--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:

NG_BUILD_MANGLE=false ng build --prod
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular-cli tree-shaking exclude component from removal
Is there a way to exclude certain components from getting removed/dropped during tree shaking? a. If YES, then how? b. If NO then...
Read more >
A gentle introduction into tree shaking in Angular Ivy
In this article I am going to explain how tree shaking happens in Angular Ivy. I will briefly explain the tree-shakable concept and...
Read more >
angular 6 tree shaking - Medium
Tree shaking is a step in a build process that removes unused code so the application becomes smaller. It can be visualised as...
Read more >
Optimize your Angular 2 Application with Tree Shaking
In that era the Angular CLI project was just getting started. Today they provide a complete build package so you should go over...
Read more >
Tree Shaking - Getting started with Syncfusion Angular
Tree Shaking is a way to remove unused modules from the final bundle file of ... Create an Angular application with Syncfusion EJ2...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found