In this final lesson, we will see how can we Publish Angular Library To Public NPM Repository which we created with the npm pack command.
npm pack
The first thing will do is we have to signup for an account with npmjs for publishing the angular library to the pubic npm repository.
Provide your credentials by running the below mention command from the terminal.
npm adduser
(Note: This is a one-time operation only and you can skip this step if you have already logged in.) Once you are logged in, we have to navigate to the dist folder of the application and then inside the library folder where we have created the news-twentyfour-0.0.1.tgz file using npm pack command.
news-twentyfour-0.0.1.tgz
.tgz
publish library using below command:
npm publish - -access public
Then we can see the published package on npm at this URL: https://www.npmjs.com/package/< library- name> Now as we have created and published our library to the public NPM repository we can install it anywhere in angular projects.
npm install — save <library-name>@0.0.1
(here 0.0.1 is the version number of a library, which is necessary)
As a good programming practice, we should have some unique names for the library we create. Because our npm’s public registry will sure have many packages with these similar names. So you can follow the approach to add your npm’s username with your library name so that it can be uniquely identified and also to avoid the errors while you publish it.
{ "name": "@__username__/news-twentyfour", "version": "0.0.1", "peerDependencies": { "@angular/common": "^10.1.1", "@angular/core": "^10.1.1" }, "dependencies": { "tslib": "^2.0.0" } }