1.概念
- 它是基于 Node.js 的网页应用程序
- 它是私有 npm registry
- 它是本地网络 proxy
- 它是可插入式应用程序
- 它相当容易安装和使用
- 我们提供 Docker 和 Kubernetes 支持
- 它与yarn, npm 和pnpm 100% 兼容
- 它forked于
sinopia@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