publlish a private npm package by using github packages

zilinrrr

nazhenhuiyi

Posted on July 19, 2022

publlish a private npm package by using github packages

BACKGROUND

Sometimes we need publish NPM package for reusing code, and we don’t want stranger to access our package,so we need publish a private npm package.

HOW TO PUBLISH

  1. Create Your Personal Acess Token in github, plz select write packages and delete packages permission. Image description
  2. Login in github registry in your terminal, plz run npm login --scope=@OWNER --registry=https://npm.pkg.github.com.If this package is in your team, scope is your team's name.
  3. create a .npmrc file in your root dir, and add a line @OWNER:registry=https://npm.pkg.github.com.
  4. modify package.json file

    • Verify the name of your package in your project's package.json. The name field must contain the scope and the name of the package. For example, if your package is called "test", and you are publishing to the "My-org" GitHub organization, the name field in your package.json should be @my-org/test.
    • Verify the repository field in your project's package.json. The repository field must match the URL for your GitHub repository. For example, if your repository URL is github.com/my-org/test then the repository field should be git://github.com/my-org/test.git.
    • Verify the files field in your project's package.json. You should include files that should be published.
  5. publish package by running npm publish.
    Image description

How To Install

  1. You should follow HOW TO PUBLISH , and complete 1st step , 2nd step and 3rd step.
  2. run npm install @OWNER/your-components or yarn add @OWNER/your-components.
💖 💪 🙅 🚩
zilinrrr
nazhenhuiyi

Posted on July 19, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related