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 地址
-
安装
npm install -g nrm
-
添加 registry 地址
nrm add npm http://registry.npmjs.org nrm add taobao https://registry.npm.taobao.org
-
切换 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的包。