客户端(本地)发布npm到私有仓库

2020-12-23  本文已影响0人  Sunshine_Boys

使用verdaccio在服务器搭建好私有仓库以后,接下来就是如何在本地上传npm包到私有仓库服务器了;
正常发布npm包到中央仓库,具体可参考博客如何开发一个npm包并发布到npm中央仓库

1.先登录私服

#未注册且私服允许注册的
npm adduser --registry=http://xxx.xxx.x.xx:4873
#输入npm账号用户名、密码和邮箱,如下:
Username: better1025
Password: 
Email: (this IS public) xxx@xx.com
Logged in as better1025 on http://xxx.xxx.x.xx:4873/.
#之前已经注册过了,就使用下面的登录命令
npm login --registry=http://xxx.xxx.x.xx:4873

2、发布npm包到私有仓库

#cd 项目目录
npm publish --registry=http://xxx.xxx.x.xx:4873

3.npm成功发布到私有仓库

http://xxx.xxx.x.xx:4873 前往查看是否成功

4.如何使用私有仓库npm包

npm install -g nrm

2.查看当前状态

$nrm ls
  npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/
  nj --------- https://registry.nodejitsu.com/
  npmMirror -- https://skimdb.npmjs.com/registry/
  edunpm ----- http://registry.enpmjs.org/

3.命令说明

nrm use <registry>: 设置使用某个镜像源。
nrm add <registry> <url> [home]: 增加一个自定义镜像源。registry表示该源的缩写,url表示该源的地址,home表示该源的主页,可以不设定。例如:nrm add n https://r.cnpmjs.org https://r.cnpmjs.org,成功会有提示:add registry n success。
nrm del <registry>: 删除一个自定义镜像源,不能删除nrm自带的。删除成功,会有提示delete registry n success。
$ nrm add slweb http://xxx.xxx.x.xx:4873 http://xxx.xxx.x.xx:4873

2.切换镜像源

nrm use slweb

安装私服包


cd到项目跟目录,使用npm install xxx (这里的xxx代表你package.json中的name也就是包名)命令就会优先去我们自己的私有仓库下载npm包,如何没有找到,则会从npm中央仓库下载
原文链接

上一篇 下一篇

猜你喜欢

热点阅读