In this lesson, we will see how can we build our angular library and also will look into how can we publish the angular library to local npm and use it.
Build Angular Library
We can use the library in locally importing through the project folder but at the user end actual implementation is that the user will install the package and it will be downloaded in the node_modules folder
So for that, we will first build our angular library which will create a bundle in the dist folder.
# ---> angular workspace folder. ng build news-twentyfour
This command will create a dist folder and inside this folder, our compiled library is stored.
Publishing Library to Local npm
As we already have built the library but for the npm package will have to build this library as an npm package, and then we can publish it to the local node package manager’s registry.
So will go to our dist/news-twentyfour/ folder and will create the
# ---> folder: dist/news-twentyfour npm pack
This will make a Pack (target) file with a
Locally Publishing has done..!! Now we can use this library in any angular application.
So lets quickly try to install the library into another angular application.
# ---> folder: other angular workspace npm install <path to folder>/dist/news-twentyfour/news-twentyfour-0.0.1.tgz