Sitemap
Aman Anurag

Aman Anurag

Angular Library

2 min readApr 23, 2019

Get started with Angular Library and Application

Press enter or click to view image in full size

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
Press enter or click to view image in full size

public-api.ts file is created where we can export the contents of the library.


ng build
shared-lib

This will create a dist folder inside the project.

Press enter or click to view image in full size
shared-lib> npm pack

This command will pack library to tarball named shared-lib-0.0.1.tgz

Press enter or click to view image in full size

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"

--

--