Hi folks,
We are used to publishing the npm packages on npmjs.com. Today, I will show how we can publish the npm packages to GitHub and the steps to use those packages.
1. Publishing Packages
Prerequisites
We need to have an account with GitHub
JavaScript native/framework based project with package.json
Add the .npmrc file to your project with the following syntax. Change the OWNER value to your GitHub account or organization name.
Publishing Process to GitHub
Create personal access token using the following steps
- Login to GitHub
- Go to Settings
- Navigate to "Developer Settings" -> "personal access tokens"
- Generate token with write:packages access permissions
- Open terminal in the project folder
- Execute the command to login
- npm login --scope=@OWNER --registry=https://npm.pkg.github.com
- When prompted,
- Username: GitHub username
- Password: Personal access token
- Public e-mail: Your email address
- Enter the following command to publish the package
- npm publish
2. Consume/Installing the packages
Prerequisites
We need to have an account with GitHub
Installation
Add the .npmrc file to your project with the following syntax. Change the OWNER value to your GitHub author or organization name.