I am currently developing an Angular library (in Angular v 8.1.0) and wondering how is it possible to have it "split in different sub-libraries"?
For example, Angular (@angular
) is split somehow in different "parts" like:
@angular/common
@angular/core
@angular/forms
- etc.
and for instance, @angular/common
has different sub-directories available to import from:
@angular/common/http
@angular/common/locale
@angular/common/testing
I am wondering how to do this kind of structuring in my own Angular library to keep different context elements independent one of each other. Let's say my library is called cool-lib
and there are different feature modules which contain their own services/components/etc: common
, featureA
, featureB
.
I would like to achieve something like this:
import { CommonService } from 'cool-lib/common';
import { FeatAComponent, FeatAService } from 'cool-lib/feature-a';
import { FeatBModule } from 'cool-lib/feature-b';
instead of having:
import {
CommonService,
FeatAComponent,
FeatAService,
FeatBModule
} from 'cool-lib';
and it even also would be nice to be able to independently bump version numbers of the different feature modules or simply having installed only those that are going to be needed without having to install the whole libary (let's say I only need featureA
).
For example, having on my package.json:
{
"dependencies": {
"cool-lib/common": "1.0.0",
"cool-lib/feature-a": "1.0.0",
"cool-lib/feature-b": "1.3.0"
}
}
or just:
{
"dependencies": {
"cool-lib/feature-a": "1.0.0"
}
}
instead of:
{
"dependencies": {
"cool-lib": "1.0.0"
}
}
I have read a lot about creating Angular libraries so far, but couldn't find this specific use case as all of them cover just the very basics of creating and publishing them on npm... so any help on this is very welcomed!