在使用npm命令时,如果直接从国外的仓库下载依赖,有时候下载速度很慢,甚至会下载不下来。这时我们可以更换npm的仓库源,提高下载速度。
查看npm源地址:
npm config get registry
更换npm源为淘宝镜像:
// 如更换为淘宝镜像
npm config set registry https://registry.npm.taobao.org/
如果设置了npm为淘宝镜像,需要恢复为默认源时:
npm config set registryhttps://registry.npmjs.org
设置好之后,记得通过 npm config get registry 查看源是否设置成功。
注意:如果只是想临时更换源地址,可以进行如下操作:
// 在使用npm命令安装包时,后面紧跟源地址
npm install packagname -g --registry=https://registry.npm.taobao.org
当直接从国外npm仓库下载依赖时,可能会遇到速度慢或下载失败的问题。解决方法是将npm的仓库源更改为淘宝镜像,通过`npmconfigsetregistryhttps://registry.npm.taobao.org/`命令设置。若需恢复默认源,可使用`npmconfigsetregistryhttps://registry.npmjs.org`。此外,若只想临时更换源,可在`npminstall`命令后添加源地址参数。
309

被折叠的 条评论
为什么被折叠?



