Angular Library
Get started with Angular Library and Application
Working on multiple projects at the same time, with very similar functionality has often resulted in copy-paste of the feature from one project to another.However with the concept of Angular library we can have these functionality added and published to npm package and used across the projects via npm dependency in root package.json file.
Get Aman Anurag’s stories in your inbox
Join Medium for free to get updates from this writer.
In this article I will create a library that will be used in other projects as npm dependency
npm install -g @angular/cli
ng new ng-library
cd ng-library
ng g lib shared-lib
public-api.ts file is created where we can export the contents of the library.
ng build shared-libThis will create a dist folder inside the project.
shared-lib> npm packThis command will pack library to tarball named shared-lib-0.0.1.tgz
Using the library in other project is very easy , we can add it into package.json file
"lib-shared" : "../libraries/dist/lib/shared/shared-lib-0.0.1.tgz"




