一、为什么要搭建npm私库
二、为什么用verdaccio 替换 sinopia
三、搭建verdaccio
[root@monitor-cicd ~]# uname -r 3.10.0-862.11.6.el7.x86_64 [root@monitor-cicd ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@monitor-cicd ~]# node -v v10.14.2
3.1 安装verdaccio
npm install -global verdaccio --unsafe-perm #--unsafe-perm 说明:npm会有生命周期,某个包会有生命周期来执行一些东西,安全起见会自动降级导致没有权限执行一些操作,通过--unsafe-perm参数来解锁该限制。
npm报权限错误参考案例:https://blog.csdn.net/weiguang1017/article/details/78813901
3.2 修改配置文件
vim /root/.config/verdaccio/config.yaml
旧:url: https://registry.npmjs.org/ (国外) 新:url: http://registry.npm.taobao.org/ (阿里云)
2)指定ip端口:
在配置文件末尾添加如下:(因为默认是localhost:4873 (弊端:只能在本机访问)) #指定ip端口 listen: 0.0.0.0:4873
其余解释:
storage: ./storage # 所有包的缓存目录 plugins: ./plugins # 插件目录 file: ./htpasswd # 用户信息存储目录
3.2 使用pm2 守护verdaccio进程
npm install -g pm2 --unsafe-perm
使用pm2启动verdaccio:
/application/nodejs/bin/pm2 start /application/nodejs/bin/verdaccio
3.3 将当前npm服务指向本地
npm set registry http://127.0.0.1:4873