Skip to content

Verdaccio搭建Maven私服

1.docker安装Verdaccio

  • 下载镜像verdaccio/verdaccio
  • 端口映射:容器端口4873
  • 容器路径:verdaccio

2.配置及使用

conf.yaml配置
  • 配置操作用户
  • 添加用户后设置
  • 所有$all用户都可以拉取,仅finemap可以推送和删除
  • 进入docker终端:/bin/sh
  • 编辑配置文件vi /verdaccio/conf/conf.yaml
yaml
packages:  
	'@*/*':    
		# scoped packages    
		access: $all    
		publish: finemap    
		unpublish: finemap    
		proxy: npmjs  

	'**':    
		# allow all users (including non-authenticated users) to read and    
		# publish all packages    
		#    
		# you can specify usernames/groupnames (depending on your auth plugin)    
		# and three keywords: "$all", "$anonymous", "$authenticated"    
		access: $all     
		# allow all known users to publish/publish packages    
		# (anyone can register by default, remember?)    
		publish: finemap    
		unpublish: finemap    
		# if package is not available locally, proxy requests to 'npmjs' registry    
		proxy: npmjs
  • 添加用户后,配置最大用户数量为2
yaml
auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd
    # Maximum amount of users allowed to register, defaults to "+infinity".
    # You can set this to -1 to disable registration.
    max_users: 2
    # Hash algorithm, possible options are: "bcrypt", "md5", "sha1", "crypt".
    # algorithm: bcrypt # by default is crypt, but is recommended use bcrypt for new installations
    # Rounds number for "bcrypt", will be ignored for other algorithms.
    # rounds: 10
用户操作
  • 创建用户
bash
npm adduser --registry http://nas.finemap.cn:4873/
  • 登录用户
bash
npm login --registry http://nas.finemap.cn:4873/
  • 查看登录用户
bash
npm whoami --registry http://nas.finemap.cn:4873/
推送项目
  • 方法一:带路径提交
bash
# 进入提交工程中,比如:finemap
npm publish --registry http://nas.finemap.cn:4873/
  • 方法二:项目中配置路径
  • 可以在 package.json 中配置 publishConfig、在npm publish推送
json
{
  "publishConfig": {
    "registry": "http://nas.finemap.cn:4873/"
  }
}
删除依赖
bash
# 强制删除:@fine/login
npm unpublish @fine/login --force --registry http://nas.finemap.cn:4873/
安装依赖
bash
# 安装组件:@fine/login
npm install @fine/login --registry http://nas.finemap.cn:4873/

3.nrm查看配置

全局安装nrm

bash
npm install -g nrm

查看已有配置

bash
nrm ls