使用 Verdaccio 搭建 Npm 私服
私服搭建部分
这部分是搭建的
安装
npm install -g verdaccio
测试是否成功
$> verdaccio
warn --- config file - /home/.config/verdaccio/config.yaml
warn --- http address - http://localhost:4873/ - verdaccio/3.0.0
如果可以访问 http://localhost:4873/
就代表可以了
pm2启动
启动是全局安装路径下的verdaccios
,
我的路径是:C:\Users\Administrator\AppData\Roaming\npm\node_modules\verdaccio\bin\verdaccio
pm2 start path/verdaccio
重启可以直接 pm2 restart your_task_id
,更多 pm2 资料可以参考 https://www.npmjs.com/package/pm2
配置信息
winds的默认配置在C:\Users\Administrator\AppData\Roaming\verdaccio\config.yaml
默认的配置解释;
# 所有软件包的目录路径,获取包和publish时仓库保存的地址。
storage: ./storage
# 包含插件的目录的路径
plugins: ./plugins
web:
title: CZR Dev Team Private 2
# 注释掉以禁用Gravatar支持
# gravatar: false
# 默认情况下,软件包为 ordercer ascendant (asc|desc)
# sort_packages: asc
auth:
htpasswd:
# 账号密码的文件地址,初始化时不存在,可指定需要手工创建。
file: ./htpasswd
# 允许注册的最大用户数量,默认为 "+inf".
# 您可以将其设置为-1以禁用注册,为-1时,不允许用户通过npm adduser注册。
# 但是,当为-1时,可以通过直接编写htpasswd file内容的方式添加用户(相当于们把每个人的信息直接写进去)。
max_users: -1
# 配置上游的npm服务器,主要用于请求的仓库不存在时到上游服务器去拉取,我给配到taobao源上
# 后期可以给禁止掉
uplinks:
npmjs:
url: https://registry.npm.taobao.org/
ccc:
url: https://czr.com/
# 配置模块。access访问下载权限,publish包的发布权限。
packages:
'@*/*':
# scoped packages
# access 表示哪一类用户可以对匹配的项目进行安装(install)
access: $authenticated
# 表示哪一类用户可以对匹配的项目进行发布和撤销(publish)
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
'**':
# 允许所有用户(包括未经身份验证的用户)读取和
# 发布所有软件包
#
# 您可以指定 usernames/groupnames (depending on your auth plugin)
# 三个关键字: "$all", "$anonymous", "$authenticated"
# $all 表示所有人(已注册、未注册)都可以执行对应的操作
# $authenticated 表示只有通过验证的人(已注册)可以执行对应操作,注意,任何人都可以去注册账户。
# $anonymous 表示只有匿名者可以进行对应操作(通常无用)
# 或者也可以指定对应于之前我们配置的用户表 htpasswd 中的一个或多个用户,这样就明确地指定哪些用户可以执行匹配的操作
access: $authenticated
# 允许所有已知用户发布/发布软件包
publish: $authenticated
unpublish: $authenticated
# 如果软件包在本地不可用,则代理请求“ npmjs”注册表
# 虽然文档里说:这里如果关闭,包没有就抛错了,但是我实际测试并不是这样的,我在npmjs里面配一个不能工作的源就可以了
proxy: npmjs
# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# 您可以指定传入连接的 HTTP/1.1 服务器的超时时间(以秒为单位)。
# 值为0会使http服务器的行为类似于8.0.0之前的Node.js版本,后者没有保持活动超时。
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:
keepAliveTimeout: 60
middlewares:
audit:
enabled: true
# log settings
logs:
- { type: stdout, format: pretty, level: http }
#- {type: file, path: verdaccio.log, level: info}
#experiments:
# # support for npm token command
# token: false
listen: 192.168.10.221:4873 # listen on all addresses