-1

I wonder if it possible to centralize the import of Angular modules? For instance, I'm using the NgbModule from @ng-bootstrap/ng-bootstrap. Do I have to import the module into each module that will use the @ng-bootstrap/ng-bootstrap features?

I thought that I can centralize those kind of import in the SharedModule and then after importing the SharedModule all dependencies will available.

I think that I have overestimated the role of the ShareModule.

Many thanks for your help

ragnar
  • 150
  • 1
  • 6
  • We take a "module-per-component" approach in most cases to prevent bloat. If something is truly shared across every module, we'll have a `shared.module.ts`, but that module is typically extremely light. – Brandon Taylor Apr 14 '22 at 15:23

1 Answers1

2

You can but it's not advised.

There is something called tree-shaking and module bundling in Angular apps. Those features are used to reduce your final bundle size.

If you create a SharedModule that you import everywhere, you loose the perks of those features and your final bundle will have duplicated code all over the place, as well as dead code.

  • 1
    Related read: [What is Tree Shaking and Why Would I Need It?](/questions/45884414/what-is-tree-shaking-and-why-would-i-need-it) – D M Apr 14 '22 at 15:15