3种方式修改 npm 源
1、终端安装
此方式为一次性使用,每次安装(或查看)都要带上 --registry
选项
npm install PACKAGE_NAME --registry https://registry.npm.taobao.org
npm info PACKAGE_NAME --registry https://registry.npm.taobao.org
2、设置 npm 的配置项
此方式为设置全局的 npm 配置项,即使关闭终端或重启电脑都不会失效。
npm config set registry https://registry.npm.taobao.org
还有其他常用命令:
npm config list -l # 查看所有配置项
npm config get [<key>] # 查看某一项的配置信息
npm config set <key> <value> # 设置某一项的配置信息
3、使用 .npmrc 文件
此方式同样为全局有效,但没有修改原始的配置项。
需要在用户目录下创建 .npmrc
文件,添加如下内容:
registry = http://registry.npm.taobao.org
当你使用第2种方式修改配置项后,你会惊奇的发现,它其实与第三种相同,也会在用户目录下创建一个
.npmrc
文件。