[ npm ] 配置與Registry管理

npm config

首先使用 npm config -h ,查看它的相關信息以及命令行。

npm config set <key> <value>  # 設置 npm 配置
npm config get [<key>]        # 獲取 npm 指定配置的值
npm config delete <key>       # 刪除 npm 指定配置
npm config list [--json]      # 列出 npm 的配置[可以以json格式輸出]
npm config edit               # 編輯 npm 配置
npm set <key> <value>
npm get [<key>]

alias: c    # 別稱,你可以用 "npm c" 等同 "npm config"

配置 Registry

方法1:

設置國內鏡像:

npm config set registry https://registry.npm.taobao.org 

設置原npm地址:

npm config set registry http://registry.npmjs.org 

方法2:

npm config edit
# 進入編輯模式
;;;;
; npm userconfig file
; this is a simple ini-formatted file
; lines that start with semi-colons are comments.
; read `npm help config` for help on the various options
;;;;
registry=http://registry.npmjs.org/

方法3:

使用 nrm 管理 registry 地址

  1. 安裝

    npm install -g nrm
    
  2. 添加 registry 地址

    nrm add npm http://registry.npmjs.org
    nrm add taobao https://registry.npm.taobao.org
    
  3. 切換 npm registry 地址

    nrm use taobao
    nrm use npm
    

    除此之外,nrm還可以管理多個第三方包管理工具的registry

    $ nrm ls # 查看所有第三方包管理工具的registry
    
    * npm -----  https://registry.npmjs.org/
      yarn ----- https://registry.yarnpkg.com
      cnpm ----  http://r.cnpmjs.org/
      taobao --  https://registry.npm.taobao.org/
      nj ------  https://registry.nodejitsu.com/
      skimdb -- https://skimdb.npmjs.com/registry
    
    
    $ nrm use cnpm  # 切換 cnpm 的 registry
    
    Registry has been set to: http://r.cnpmjs.org/
    

後記

因爲本人有在嘗試將包發佈到npm,但是由於國內環境一般都是將源設置爲淘寶鏡像,但是這個registry的情況是不能發佈的。名稱都要手動切換到npm官方源發佈後,再切換回來。因此尋找到一個方便切換,指令好記的管理Registry的包。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章