前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >搭建npm私有仓库——verdaccio

搭建npm私有仓库——verdaccio

作者头像
Karl Du
发布2023-10-20 18:42:12
5530
发布2023-10-20 18:42:12
举报
文章被收录于专栏:Web开发之路Web开发之路

前言

Verdaccio 是一个简单的、零配置要求的本地私有 npm 注册表。无需整个数据库即可开始!Verdaccio 开箱即用,带有自己的小型数据库,并且能够代理其他注册表(例如 npmjs.org),并在此过程中缓存下载的模块。对于那些希望扩展其存储功能的人,Verdaccio 支持各种社区制作的插件,以连接到服务,例如 Amazon 的 s3、Google Cloud Storage或创建您自己的插件

Verdaccio is a lightweight private npm proxy registry built in Node.js

verdaccio是基于node.js的,所以在我们的服务器上需要安装node

Linux 部署

1、安装:

代码语言:javascript
复制
npm install -g verdaccio	# using npm
yarn global add verdaccio	# or using yarn

2、运行:

代码语言:javascript
复制
$> verdaccio
warn --- config file  - /home/.config/verdaccio/config.yaml
warn --- http address - http://localhost:4873/ - verdaccio/3.0.0

Windows 部署

1、安装 nodejs

我们可以安装最新版本,==注意:Verdaccio 5 需要 Node.js v12==

nodejs 下载地址

2、安装 verdaccio

代码语言:javascript
复制
mkdir c:verdaccio 		# 创建目录
cd c:verdaccio			# 进入目录
npm install verdaccio		# 安装 verdaccio

3、创建 config.yaml

在当前目录创建config.yaml文件

4、Windows 服务设置

自行选择使用nssm或者winsw,原理都一样。本文使用nssm

  • 下载nssm
  • 添加包含nssm.exe的路径到PATH
  • 打开管理命令
  • 运行nssm install verdaccio,至少必须填写应用程序tab Path,启动目录和参数字段。 假设在系统路径中以及c:verdaccio位置用node安装,以下的值将起作用:
    • Path: node
    • Startup directory: c:verdaccio
    • Arguments: c:verdaccionode_modulesverdacciobuildlibcli.js -c c:verdaccioconfig.yaml
  • 启动服务sc启动verdaccio
image.png
image.png

查看nssm详细使用教程

配置

我们需要对 verdaccio 进行一些基本设置,打开配置文件:config.yaml

查看verdaccio详细配置

设置网站名

代码语言:javascript
复制
web:  
title: 'Sixpence NPM'

设置用户验证的文件

代码语言:javascript
复制
auth:
  htpasswd:  
  file: ./htpasswd  
  max_users: 1000 #默认为1000,改为-1,禁止注册  

代理配置

uplinks里设置源,然后在packages里设置proxy

代码语言:javascript
复制
# a list of other known repositories we can talk to
uplinks:
  taobao:
    url: https://registry.npm.taobao.org/
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: taobao 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: $authenticated
    unpublish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: taobao npmjs

配置权限管理

代码语言:javascript
复制
packages:  
   ‘@/’:  
  #表示哪一类用户可以对匹配的项目进行安装 【$all 表示所有人都可以执行对应的操作,$authenticated 表示只有通过验证的人可以执行对应操作,$anonymous 表示只有匿名者可以进行对应操作(通常无用)】  
  access: $all  
  #表示哪一类用户可以对匹配的项目进行发布  
  publish: $authenticated  
‘*’:  
  #表示哪一类用户可以对匹配的项目进行安装  
  access: $all  
  #表示哪一类用户可以对匹配的项目进行发布  
  publish: $authenticated  
  #如果一个npm包不存在,它会去询问设置的代理。  
  proxy: npmjs  

日志输出设置

代码语言:javascript
复制
logs:  
   -{type: stdout, format: pretty, level: http}  
  #-{type: file, path: verdaccio.log, level: info}  

修改监听的端口

代码语言:javascript
复制
listen: 0.0.0.0:4873  

示例

完整配置如下:

代码语言:javascript
复制
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#

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

web:
  title: Sixpence Verdaccio
  # comment out to disable gravatar support
  # gravatar: false
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc
  # convert your UI to the dark side
  # darkMode: true

# translate your registry, api i18n not available yet
# i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
#   web: en-US

auth:
  htpasswd:
    file: ./htpasswd
    # Maximum amount of users allowed to register, defaults to "+inf".
    max_users: -1
    # You can set this to -1 to disable registration.
    # max_users: 1000

# a list of other known repositories we can talk to
uplinks:
  taobao:
    url: https://registry.npm.taobao.org/
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: taobao 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: $authenticated
    unpublish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: taobao 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.
# 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
#  # support for the new v1 search endpoint, functional by incomplete read more on ticket 1732
#  search: false

# This affect the web and api (not developed yet)
#i18n:
#web: en-US

listen: 0.0.0.0

遇到的问题

问题 1

运行npm install出现 thon Python is not set from command line or npm configuration 解决方案

解决方案

代码语言:javascript
复制
npm install -g -p windows-build-tools
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020/10/16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • Linux 部署
  • Windows 部署
  • 配置
    • 设置网站名
      • 设置用户验证的文件
        • 代理配置
          • 配置权限管理
            • 日志输出设置
              • 修改监听的端口
                • 示例
                • 遇到的问题
                  • 问题 1
                    • 解决方案
                    相关产品与服务
                    数据库
                    云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
                    领券
                    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档