I have the below mono repo folder structure for my Angular application.
I am using library1 and library2 in app1/app2, also publishing both the libraries as .tgz separately to be consumed by other angular applications.
I am using ng-packagr to Compile and package Angular libraries in Angular Package Format (APF).
to create library using below commands :
**ng build --library1**
**npm pack**
In directory/angular.json
"projects": {
"library1": {
"root": "libs/library1",
"sourceRoot": "libs/library1/src",
"projectType": "library",
"prefix": "library1",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "libs/library1/tsconfig.lib.json",
"project": "libs/library1/ng-package.json"
},
"configurations": {
"production": {
"project": "libs/library1/ng-package.prod.json"
}
}
}
}
In directory/libs/library1/ng-package.json
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/library1",
"lib": {
"entryFile": "src/index.ts"
}
}
What I Need :
Now I want to combine library1 and library 2 to create a single library may be libraryAll(libraryAll.tgz) which will export libray1 and library 2.
Also I need a shared module which will be consumed by both libraries and will be a part of final library package.
To combine two libraries into one i suggest you to create a third one that imports the first two and expose it with a different index.ts . This if you want to maintains it separately in all means.
Both the first and second library needs to be compiled before are used and exposed by the third one.
Ex. LibraryAllModule that exports Library1Module and Library2Module.
The index.ts will looks like:
Or an other approach it could be to report the code from both libraries into a new library divided by modules.
The index.ts will looks like this:
By combining the 2 libraries into a common library it will be also easier for you to crate a common module to share between both. You can declare it in the folder 'libraryAll' and import it in both libraries then.