github作为npm私服

返回
Author Avatar
钢翼
2022-04-04
编程
70

1.在github上新建私有仓库

假设仓库名为 npm-repo

2.在package.json中添加repository

{	
  "name":"@{github用户名}/{包名}"
  "repository": {
    "type": "git",
    "url": "https://github.com/{github用户名}/npm-repo"
  }
}

3.添加.npmrc文件

@{github用户名}:registry=https://npm.pkg.github.com/{github用户名}
//npm.pkg.github.com/:_authToken={有仓库权限的token}

registry前限定用户名,这样不会影响其他第三方包的下载

4.添加排除文件.npmignore

排除node_modules等不需要的文件和文件夹

5.发布项目到github私服

npm publish

npm不同于maven,没有快照版,发布前记得升级版本号。

6.安装github私服上的npm包

需要有.npmrc文件,参考第3点

# 不能使用yarn指令代替npm
npm install @{github用户名}/{包名}