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
You have to export NavigationModule
in the LibraryModule
, not NavigationSidebarComponent
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.