ngtsc will avoid emitting generated imports that would create an import cycle in the user's program. The main way such imports can arise is when a component would ordinarily reference its dependencies in its component definition `directiveDefs` and `pipeDefs`. This requires adding imports, which run the risk of creating a cycle. When ngtsc detects that adding such an import would cause this to occur, it instead falls back on a strategy called "remote scoping", where a side- effectful call to `setComponentScope` in the component's NgModule file is used to patch `directiveDefs` and `pipeDefs` onto the component. Since the NgModule file already imports all of the component's dependencies (to declare them in the NgModule), this approach does not risk adding a cycle. It has several large downsides, however: 1. it breaks under `sideEffects: false` logic in bundlers including the CLI 2. it breaks tree-shaking for the given component and its dependencies See this doc for further details: https://hackmd.io/Odw80D0pR6yfsOjg_7XCJg?view In particular, the impact on tree-shaking was exacerbated by the naive logic ngtsc used to employ here. When this feature was implemented, at the time of generating the side-effectful `setComponentScope` call, the compiler did not know which of the component's declared dependencies were actually used in its template. This meant that unlike the generation of `directiveDefs` in the component definition itself, `setComponentScope` calls had to list the _entire_ compilation scope of the component's NgModule, including directives and pipes which were not actually used in the template. This made the tree- shaking impact much worse, since if the component's NgModule made use of any shared NgModules (e.g. `CommonModule`), every declaration therein would become un-treeshakable. Today, ngtsc does have the information on which directives/pipes are actually used in the template, but this was not being used during the remote scoping operation. This commit modifies remote scoping to take advantage of the extra context and only list used dependencies in `setComponentScope` calls, which should ameliorate the tree-shaking impact somewhat. PR Close #39662
Angular - One framework. Mobile & desktop.
Angular is a development platform for building mobile and desktop web applications
using Typescript/JavaScript and other languages.
Contributing Guidelines
·
Submit an Issue
·
Blog
Documentation
Get started with Angular, learn the fundamentals and explore advanced topics on our documentation website.
Advanced
Development Setup
Prerequisites
- Install Node.js which includes Node Package Manager
Setting Up a Project
Install the Angular CLI globally:
npm install -g @angular/cli
Create workspace:
ng new [PROJECT NAME]
Run the application:
cd [PROJECT NAME]
ng serve
Quickstart
Ecosystem
Changelog
Learn about the latest improvements.
Upgrading
Check out our upgrade guide to find out the best way to upgrade your project.
Contributing
Contributing Guidelines
Read through our contributing guidelines to learn about our submission process, coding rules and more.
Want to Help?
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues in the hotlist: community-help.
Code of Conduct
Help us keep Angular open and inclusive. Please read and follow our Code of Conduct.
Community
Join the conversation and help the community.
Love Angular? Give our repo a star ⭐ ⬆️.