Angular Library Modules export components, services and others from module

前端 未结 2 441
栀梦
栀梦 2021-01-14 09:46

I have created an Angular Library. In my Library I would it like it to be clean by having feature modules inside them:

Example:

Libr         


        
相关标签:
2条回答
  • 2021-01-14 10:16

    You have to export NavigationModule in the LibraryModule, not NavigationSidebarComponent

    0 讨论(0)
  • 2021-01-14 10:16

    I think you don't need a top level "Library module" at all. Look at the source tree for @angular/material: I think they used to have a material.module and got rid of it, and now the root only has a completely empty index.ts. Each component has its own module, and modules like the one for MatAutocomplete import modules that they depend on (like MatOptionModule) and re-export them.

    I've been converting a project of mine to a similar model, and doing research to figure out the current best practices for module structure. I believe Material converted from a "monolithic library" approach, where you were encouraged to import { MatAutocompleteModule } from "@angular/material" to one module per component (or group of related components), because this approach allows you to distribute the library as a single package, but still benefit from tree-shaking, so only the modules that are actually used will be included in your build.

    0 讨论(0)
提交回复
热议问题