nrm、npm、yarn 等配置处理

1,232 阅读2分钟

一、nrm

nrm(npm registry manager )是npm的镜像源管理工具。

1、全局安装nrm

npm i nrm -g

2、nrm有自带默认配置,*为当前的配置

nrm ls

npm ----------------- registry.npmjs.org/

yarn ---------------- registry.yarnpkg.com/

tencent ------------- mirrors.cloud.tencent.com/npm/

cnpm ---------------- r.cnpmjs.org/

*taobao -------------- registry.npmmirror.com/

npmMirror ----------- skimdb.npmjs.com/registry/

*的那个是当前使用的镜像源。

3、切换当前源地址

nrm use <registryName>

nrm use taobao

4、删除源地址

nrm del <registryName>

nrm del taobao

5、添加源地址

nrm add <registryName> <registryUrl>

nrm add laifp http://10.8.82.118:4873/

这个时候执行 nrm ls 会发现多了条。

6、测试时间(下载速度)

nrm test <registryName> 

nrm test taobao image.png

我们可以多次测量不同镜像源的响应时间,找到网速最好的那个,然后切换过去即可!

二、npm 配置

1、查看 npm 的配置

npm config ls

image.png

2、查看 npm 全局安装位置

npm get prefix or npm prefix -g

注意与npm prefix 的不同,如下图

image.png

3、设置 npm 全局安装的位置

npm config set prefix "E:\nodejs-npm\node_modules\node_global"

4、查询 npm cache 全局安装的位置

npm get cache

5、设置 npm cache 全局安装的位置

npm config set cache "E:\nodejs-npm\node_modules\node_cache"

6、查询 npm bin 全局安装的位置

npm -g bin

image.png

三、yarn 配置

1、查看 yarn 的配置

yarn config list

注意与 npm 不同,npm 是使用 npm config ls

image.png

2、查看 yarn 全局安装位置

yarn global dir

默认安装位置为:C:\Users\laifeipeng\AppData\Local\Yarn\Data\global

我电脑设置的为:E:\nodejs-npm\node_modules\node_global__yarn

3、设置 yarn 全局安装的位置

yarn config set global-folder "E:\nodejs-npm\node_modules\node_global__yarn"

4、查询 yarn cache 全局安装的位置

yarn cache dir

默认安装位置为: C:\Users\laifeipeng\AppData\Local\Yarn\Cache\v6

我电脑设置的为: E:\nodejs-npm\node_modules\node_cache__yarn\v6

5、设置 yarn cache 全局安装的位置

yarn config set cache-folder "E:\nodejs-npm\node_modules\node_cache__yarn\v6"

四、其他

1、.nrmrc .yarnrc 文件

默认位置在: C:\Users\laifeipeng,可以直接看里面的内容。

2、使用某个镜像源下载依赖包的几种方式

  • 项目文件夹增加 .npmrc or .yarnrc 里面写镜像源 registry=https://registry.npmmirror.com/

  • 安装时临时设置镜像源 npm --registry=https://registry.npmmirror.com/ install (yarn 类似)