verdaccio搭建私有npm仓库

搭建私有的npm仓库

在私服上部署私有的npm仓库,一方面
阅读原文

verdaccio

1
2
3
npm install verdaccio -g  // 全局安装verdaccio

verdaccio // 运行verdaccio

verdaccio install

如何使用

1
2
3
4
5
6
7
8
# 当前npm 服务指向 本地 
npm set registry http://localhost:4873
# 注册用户
npm adduser –registry http://localhost:4873
# 按照提示输入userName 和 password,email

#查看当前用户,是否是注册用户.
npm who am i # 提示userName

进入工程目录发布私有package

1
npm publish

publish

就成功发布了一个私有的包,就可以在其他模块里面使用 npm install [package name] 来安装了,
而私有npm 里面不包含的包,例如你要安装一个vue ,webpack 这样的包,找不到的话,会被代理到 npm.js 官网去下载,并且会帮你缓存在 ./storage 文件夹里面. 再次下载,就能体验飞一般的速度了,当一个小团队使用的时候效果更佳.

由于考虑到时常会切换仓库来源,我是用了nrm ,一个仓库管理器,实际上就是 简化以下命令 npm set registry [url]

其他

npm常用命令

1
2
3
4
5
npm config set registry https://registry.npm.taobao.org  # 通过config命令设置国内镜像
npm config set registry http://registry.npmjs.org # 原npm地址
npm config get registry # 如何检测镜像是否设置成功呢?即查看镜像的配置结果

npm cache clean --force # 清除npm缓存

安装npm 仓库管理

nrm(node registry manager)

  • 使用nrm 进行npm registry地址管理和切换

    1
    npm install -g nrm
  • 添加sinopia/verdaccio 仓库地址

    1
    nrm add myPrivateNpm http://xxx.xxx.xx.xx:4873 #myPrivateNpm是给私有仓库起一个名字,后面是sinopia/verdaccio运行私有仓库的地址

切换私有仓库

1
nrm use myPrivateNpm # 使用私有npm仓库
初到贵宝地,有钱的给个钱场,没钱的挤一挤给个钱场