In GitHub every repository can publish packages, which can be used as dependencies in other projects. There are two type npm registry where we can publish packages,
- npm registry
- GitHub npm registry
Which one I should use ? It's up to you, can try both of them . In this article we are on the GitHub way.
Naming rule
Name of the package should include organization/username and will look like
@organization/name_of_the_pacakage
So adjust name in package.json
Repository
Don' forget to publish the repository and add it to the package file as follows
"repository":{
"url": "git://github.com/org_name/some_repo.git"
}
Access Token
We have to use the personal access token to authenticate, we can add the secret to the .npmrc file, so that need not authenticate manually.
Requirements
All thing need to publish a regular npm package also require for Github Package, package.json, readme.md and build project. Additionally requires .npmrc file for registry configuration.
.npmrc
This file can contain the registry information and authentication secrets, we need not expose this file to repository, so that add the file to the .gitignore
//.gitignore
.npmrc
node_modules
In the .npmrc include the registry information along with organization / owner .
@owner:registry=https://npm.pkg.github.com
npm.pkg.github.com/:_authToken=TOKEN
Replace the owner with user/org and TOKEN with personal token generated.
Publish
Let's jump into terminal issue the npm publish command and it will take few minutes to update. The package will list on the repository as well as on user/org profile page.
Update
How to update package ? Can't do that ! instead publish new version by change the version in package.json and publish new one.
Remove
For removing, there is dedicated delete button in relevant package.
following npm posts may help you
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.