Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create angular 6 library with multiple modules

Tags:

angular6

I am looking for a way to create angular 6 (by Angular 6 CLI may be) library with multiple modules that can be imported each one itself according developer`s needs.

Till now I found only tutorials that describe creating simple libraries with a couple components. And all of them must be imported by the library NgModule. But the goal is to be able import some of the modules to the production app without importing all other stuff (components etc.) from the library module.

like image 851
Itzhak Galitch Avatar asked Jun 24 '18 14:06

Itzhak Galitch


People also ask

Can an Angular app have multiple modules?

The root module is the main module in an Angular application. It is generated by the Angular CLI as AppModule and bootstrapped when the application starts. Every other Angular module depends either directly or indirectly on the root module. Only one root module can exist in an Angular application.

Can we create modules inside modules in Angular?

yes you can use modules and subModules and i advice you to use Lazy Loading pattern, when your application will be bigger and bigger you will have a big performance problems because of the bundle size and the time it takes for loading.

How many modules should Angular app have?

Every Angular application has at least one module, the root module.


1 Answers

Try ng-packagr. Here is the link with an example to create angular library using ng-packagr and export single module. But you can create as many modules as you want and export them.

The exported modules can be imported independently from the library.

like image 96
byj Avatar answered Feb 14 '23 01:02

byj