私有NPM库Verdaccio的使用手册

本文介绍了Verdaccio作为私有npm registry的用途,包括其作为Node.js应用、本地网络proxy和可插拔特性的特点。详细讲述了在Windows 10上服务端的搭建步骤,并提供了客户端的使用建议,如使用npr管理和pm2托管Verdaccio。此外,还涵盖了发布到私有仓库和下载包的操作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.概念

  • 它是基于 Node.js 的网页应用程序
  • 它是私有 npm registry
  • 它是本地网络 proxy
  • 它是可插入式应用程序
  • 它相当容易安装和使用
  • 我们提供 Docker 和 Kubernetes 支持
  • 它与yarn, npm 和pnpm 100% 兼容
  • forkedsinopia@1.4.0并且100% 向后兼容
  • Verdaccio 表示意大利中世纪晚期fresco 绘画中流行的一种绿色的意思

2.服务端搭建

基于 windows10 进行搭建

// 安装 verdaccio
npm install -g verdaccio

// 加上–unsafe-perm的原因是防止报 grywarn 权限的错
npm install -g verdaccio --unsafe-perm

// 启动
verdaccio

3.客户端使用

// 更换 npm 库
npm set registry http://localhost:4873/

tips:

① 推荐使用 npr 对 npm registry 进行统一管理,具体使用如下

// 安装 nrm
npm install -g nrm

// 添加地址到 nrm 中
nrm add [registry name] [registry address] 
nrm add verdaccio http://localhost:4873/

// 查看 nrm 镜像源地址
nrm ls

* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/ 
  verdaccio --- http://localhost:4873/

// nrm 切换 registry 地址
nrm use verdaccio

② 推荐使用 pm2 对 verdaccio 进行托管

// 安装 pm2
npm install -g pm2 --unsafe-perm

// 使用 pm2 启动 verdaccio
pm2 start verdaccio

// 查看 pm2 守护下的进程 verdaccio 的实时日志
pm2 show verdaccio 

3.1 发布

// 注册
npm adduser --registry http://localhost:4873/

// if you use HTTPS, add an appropriate CA information ("null" means get CA list from OS)
npm set ca null

现有一 npm-test 文件夹需要打包至私有仓库,如何执行?

// 在 npm-test 文件夹根目录下执行 npm init, 初始化包填写信息
npm init

// 已经切换到我们私服地址的情况下
npm publish         

// 未切换到我们的私服时,直接加后缀可以发布到私服上
npm publish --registry http://localhost:4873/ 

// 还可以在 package.json 中加入 publishConfig,就可以直接发布,无需设置仓库
"publishConfig": {
    "registry": "http://localhost:4873/"
}

3.2 下载

npm install npm-test
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值