安装verdaccio
- 安装node和npm,参考《NodeJS、NPM、CNPM安装.note》
- 安装verdaccio(加上–unsafe-perm的原因是防止报grywarn权限的错)
npm install -g verdaccio --unsafe-perm
- 安装完成后直接输入
verdaccio
命令即可运行
C:\Users\Administrator>"node" "C:\Users\Administrator\AppData\Roaming\npm\\node
_modules\verdaccio\bin\verdaccio"
warn --- config file - C:\Users\Administrator\AppData\Roaming\verdaccio\config
.yaml
warn --- Verdaccio started
warn --- Plugin successfully loaded: verdaccio-htpasswd
warn --- Plugin successfully loaded: verdaccio-audit
warn --- http address - http://localhost:4873/ - verdaccio/4.3.5
- 默认配置如下图所示
# 所有包的缓存目录
storage: ./storage
# 插件目录
plugins: ./plugins
#开启web 服务,能够通过web 访问
web:
# WebUI is enabled as default, if you want disable it, just uncomment this line
#enable: false
title: Verdaccio
#验证信息
auth:
htpasswd:
# 用户信息存储目录
file: ./htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
#max_users: 1000
# a list of other known repositories we can talk to
#公有仓库配置
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'@*/*':
# scoped packages
access: $all
publish: $authenticated
#代理 表示没有的仓库会去这个npmjs 里面去找 ,
#npmjs 又指向 https://registry.npmjs.org/ ,就是上面的 uplinks 配置
proxy: npmjs
'**':
# 三种身份,所有人,匿名用户,认证(登陆)用户
# "$all", "$anonymous", "$authenticated"
#是否可访问所需要的权限
access: $all
#发布package 的权限
publish: $authenticated
# 如果package 不存在,就向代理的上游服务发起请求
proxy: npmjs
# To use `npm audit` uncomment the following section
middlewares:
audit:
enabled: true
# 监听的端口 ,重点, 不配置这个,只能本机能访问
listen: 0.0.0.0:14873
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: verdaccio.log, level: info}
- 查看npm配置镜像
npm config get registry
https://registry.npmjs.org/
https://registry.npm.taobao.org/
- 配置当前npm 服务指向verdaccio私服
npm set registry http://localhost:4873
- 注册用户
npm adduser --registry http://localhost:4873
按照提示输入userName 和 password,email
wayken 123456 [email protected]
- 查看当前用户,是否是注册用户
npm who am i
- 发布包
npm publish --registry http://localhost:4873
- 浏览器访问:http://localhost:4873/
就成功发布了一个私有的包
- 其他项目引入包
在其他模块里面使用 npm install [package name]
来安装了
说明
- Windows配置文件所在路径
C:\Users\Administrator\AppData\Roaming\verdaccio
- 修改私有仓库为用cnpm仓库
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'@*/*':
#npmjs 又指向 https://registry.npmjs.org/ ,就是上面的 uplinks 配置
proxy: npmjs
常用的仓库地址
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一直失败
解决:将nodejs8.16.0升级到最新版