Verdaccio使用配置总结

1,085 阅读1分钟

Verdaccio使用问题总结

verdaccio官网地址

1. 安装环境

2. 给配置文件中配置的文件路径给予写权限

这里以docker.yaml为例

storage: /verdaccio/storage/data
plugins: /verdaccio/plugins
auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd
		# You can set this to -1 to disable registration. // 禁用注册:将会提示code E409
    # max_users: 1000

3. 上行链路与代理

链路:类似node_modules,一层一层往上找 代理:配置上行链路中的一个或者多个,npm,pnpm配置npmjs,yarn配置yarn,cnpm配置taobao;有的业务仓库使用lerna + yarn,执行lerna bootstrap时一定要配置代理yarn

# https://verdaccio.org/docs/configuration#uplinks
# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
  yarn:
    url: https://registry.yarnpkg.com/
    timeout: 10s
  taobao:
    url: https://registry.npmmirror.com/
    timeout: 10s

# Learn how to protect your packages
# https://verdaccio.org/docs/protect-your-dependencies/
# https://verdaccio.org/docs/configuration#packages
packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: npmjs yarn taobao

  '**':
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: npmjs yarn taobao

4. 其他问题

如果出现4.2以下问题可能是服务器不稳定,可以加上4.1的配置,如果还是不行,那就是服务器太不稳定了,没办法了

4.1、允许离线发布

publish:
  allow_offline: true

4.2、问题

  • npm addUser、npm login命令卡着不动
  • 503 Service Unavailable
  • E503 one of the uplinks is down,refuse to publish
  • timeout 1032ms,超时了

5. 完整配置

# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins

# https://verdaccio.org/docs/webui
web:
  title: Verdaccio

# https://verdaccio.org/docs/configuration#authentication
auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd

i18n:
  web: zh-CN

# https://verdaccio.org/docs/configuration#uplinks
# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
  yarn:
    url: https://registry.yarnpkg.com/
    timeout: 10s
  taobao:
    url: https://registry.npmmirror.com/
    timeout: 10s

# Learn how to protect your packages
# https://verdaccio.org/docs/protect-your-dependencies/
# https://verdaccio.org/docs/configuration#packages
packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: npmjs yarn taobao

  '**':
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: npmjs yarn taobao

publish:
  allow_offline: true
server:
  keepAliveTimeout: 60
listen: 0.0.0.0:4873
middlewares:
  audit:
    enabled: true
logs: { type: stdout, format: pretty, level: http }