Aldebaran

人生最棒的感觉,就是你做到别人说你做不到的事。

0%

使用Verdaccio搭建npm仓库

指原莉乃

logo

使用verdaccio来搭建npm私有仓库

verdaccio 的特点:

  • 不同步拉取npm库,占据大量硬盘,没有硬盘被撑爆的问题;
  • 安装配置极其简单,不需要数据库;
  • 支持配置上游registry配置,拉取即缓存;
  • 支持forever及pm2守护进程管理;
  • 私有npm package 管理
  • 支持 docker 等应用容器

安装verdaccio

  • NodeJS

      $ cd /usr/local/src
      $ wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz
      $ tar xf node-v8.11.3-linux-x64.tar.xz
      $ mv node-v8.11.3-linux-x64 /usr/local
      $ ln -s /usr/local/node-v8.11.3-linux-x64 /usr/local/node
      $ ln -s /usr/local/node/bin/npm /usr/local/bin/npm
      $ ln -s /usr/local/node/bin/node /usr/local/bin/node
      $ ln -s /usr/local/node/bin/npx /usr/local/bin/npx
    
  • verdaccio

    全局安装verdaccio

      $ npm install --global verdaccio
    

    查看配置文件

      $ cat .config/verdaccio/config.yaml
    
      # 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
      #
    
      # 配置WEB UI界面
      web :
          title : '37376NPM'
          #logo : logo.png
    
      # path to a directory with all packages
      storage: ./storage
    
      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
      cnpmjs:
          url: https://registry.npm.taobao.org
    
      packages:
      '@*/*':
          # scoped packages
          access: $all
          publish: $authenticated
          proxy: npmjs
    
      # **         # 匹配任意包
      # @*/*       # 匹配任意 scope 包
      # @npmuser/* # 匹配 scope 为 npmuser 的包
      # npmuser-*  # 匹配包名有 npmuser- 前缀的包
      '**':
          # 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 packages
          # (anyone can register by default, remember?)
          publish: $authenticated
    
          # if package is not available locally, proxy requests to 'npmjs' registry
          proxy: cnpmjs
    
      # To use `npm audit` uncomment the following section
      middlewares:
      audit:
          enabled: true
    
      # log settings
      logs:
      - {type: stdout, format: pretty, level: http}
      #- {type: file, path: verdaccio.log, level: info}
    
      listen: 192.168.99.131:4873
    

    PM2启动 verdaccio

      $ sudo npm install pm2 -g
      $ pm2 start verdaccio