Erez Shlomo
Erez Shlomo

Reputation: 2282

How does Angular handle non-imported modules from Angular libraries?

I'm currently running an Angular 12 application and importing some Angular libraries into it.

Now, let's say I'm importing a heavy angular library, ng add huge-sized-library, and this library exports a lot of Angular Modules.

How does import only one small module from the heavy library will affect the application size?

Upvotes: 2

Views: 572

Answers (1)

rveerd
rveerd

Reputation: 4006

Only the modules that you import will be included in the application build. The other modules will not be used in the build or removed by tree shaking.

For example, the ng-bootstrap library is setup in this way.

Whether this works correctly might depend on the setup of the library. You can check which modules are actually included in the build by using webpack-bundle-analyzer or similar tools. You need to add the --stats-json option to ng build to generate the required input for these tools.

Upvotes: 2

Related Questions