zoukankan      html  css  js  c++  java
  • 搭建私有npm私库(使用verdaccio)

    搭建 npm 离线服务器

    为什么要搭建npm 服务器

    原因:

    1. 公司内部开发的私有包,统一管理,方便开发和使用
    2. 安全性,由于公司内部开发的模块和一些内容并不希望其他无关人员能够看到,但是又希望内部能方便使用
    3. 加速,自己搭建npm 服务器,本身可以自带常用package的缓存, cnpm 有一些包存在路径问题,而npm 的速度有些感人,自建的服务器会缓存下载过的包,能节省时间

    搭建方法 使用verdaccio

    verdaccio 是 sinopia 开源框架的一个fork ,但是由于sinopia 两年前就已经没有人维护了,由于网上搜的都是sinopia,但我实际使用了一波后,坑不要太多,哭死…….. 而且由于没人维护,所有bug ,什么的自己去看源码解决吧, 所以果断弃坑, 找到了这个verdaccio

    安装

    使用npm 全局安装即可

    npm install –global verdaccio

    运行

    安装完成后直接输入 verdaccio 命令即可运行

    verdaccio 
    运行示例 
    运行示例

    后面的yaml 是默认的配置文件,4873端口表示默认端口,现在我们可以通过修改默认的配置文件来符合我们的需求.

    verdaccio的全部配置

    默认配置如下图所示

    # #号后面是注释
    # 所有包的缓存目录
    storage: ./storage
    # 插件目录
    plugins: ./plugins
    
    #开启web 服务,能够通过web 访问
    web:
      # WebUI is enabled as default, if you want disable it, just uncomment this line
      #enable: false
      title: Verdaccio
    #验证信息
    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/
    
    packages:
      '@*/*':
        # scoped packages
        access: $all
        publish: $authenticated
    
        #代理 表示没有的仓库会去这个npmjs 里面去找 ,
        #npmjs 又指向  https://registry.npmjs.org/ ,就是上面的 uplinks 配置
        proxy: npmjs
    
      '**':
        # 三种身份,所有人,匿名用户,认证(登陆)用户
        # "$all", "$anonymous", "$authenticated"
    
        #是否可访问所需要的权限
        access: $all
    
        #发布package 的权限
        publish: $authenticated
    
        # 如果package 不存在,就向代理的上游服务发起请求
        proxy: npmjs
    
    # To use `npm audit` uncomment the following section
    middlewares:
      audit:
        enabled: true
    # 监听的端口 ,重点, 不配置这个,只能本机能访问
    listen: 0.0.0.0:4873
    # log settings
    logs:
      - {type: stdout, format: pretty, level: http}
      #- {type: file, path: verdaccio.log, level: info}

    如何使用

    #当前npm 服务指向 本地 
    npm set registry http://localhost:4873 
    # 注册用户 
    npm adduser –registry http://localhost:4873

    按照提示输入userName 和 password,email

    输入后就注册完成,

    #查看当前用户,是否是注册用户. 
    npm who am i

    最后一步就是创建一个文件夹,按照npm publish 的标准格式,创建一个私有的package

    # 发布包 
    npm publish

    这里写图片描述

    就成功发布了一个私有的包,

    就可以在其他模块里面使用 npm install [package name] 来安装了, 
    而私有npm 里面不包含的包,例如你要安装一个vue ,webpack 这样的包,找不到的话,会被代理到 npm.js 官网去下载,并且会帮你缓存在 ./storage 文件夹里面. 再次下载,就能体验飞一般的速度了,当一个小团队使用的时候效果更佳.

    自然如果你还是不喜欢npm ,想用cnpm ,那么可以去修改配置

    uplinks:
      npmjs:
        url: https://registry.npmjs.org/
    
    packages:
      '@*/*':
        #npmjs 又指向  https://registry.npmjs.org/ ,就是上面的 uplinks 配置
        proxy: npmjs
    
    #常用的仓库地址
      npm ---- https://registry.npmjs.org/
      cnpm --- http://r.cnpmjs.org/
      taobao - https://registry.npm.taobao.org/
      nj ----- https://registry.nodejitsu.com/
      rednpm - http://registry.mirror.cqupt.edu.cn/
      npmMirror  https://skimdb.npmjs.com/registry/
      edunpm - http://registry.enpmjs.org/

    由于考虑到时常会切换仓库来源,我是用了nrm ,一个仓库管理器,实际上就是 简化以下命令

    npm set registry [url]

    转自 https://blog.csdn.net/qq_29594393/article/details/81587989

  • 相关阅读:
    Version Control System, IntelliJ IDEA, Create a Git Repository for a Project and push to multiple remotes
    SWOT, Challenges to upgrade to MacOS Big Sur (Version 11.0.1)
    How to extract text from PDF(Image) files, OCR
    How to install NetSuite SuiteCloud plug-in to WebStorm
    How to use NetSuite SDF CLI, CLI for Node.js on Mac, suitecloud command
    How to use NetSuite SDF to download bundles/components
    How to run a NetSuite scheduled script at every month end
    js 如何让forEach可以break?
    How to setup oAuth 1.0 in NetSuite RESTlet API 如何在NetSuite中设置RESTlet API的oAuth认证
    关于带宽与网速和用户体验
  • 原文地址:https://www.cnblogs.com/RexSheng/p/9552641.html
Copyright © 2011-2022 走看看