Node.js 包管理器配置包缓存位置
npm
查看配置
npm config lsornpm config list所有配置npm config list -lnpm config get xxx获取某配置
各种目录配置
npm config set prefix D:\...\npm\global # 全局
npm config set cache D:\...\npm\cache # 缓存
pnpm
查看配置
pnpm config list
各种目录配置
pnpm config set store-dir=D:\...\pnpm\store
pnpm config set state-dir=D:\...\pnpm\state
pnpm config set cache-dir=D:\...\pnpm\cache
pnpm config set global-dir=D:\...\pnpm\global
pnpm config set global-bin-dir=D:\..\pnpm\global
yarn 1.x
使用 yarn config list查看所有已配置的信息
改变 yarn 缓存路径
yarn config set cache-folder <path>
或者通过环境变量 YARN_CACHE_FOLDER 指定缓存目录
YARN_CACHE_FOLDER=<path> yarn <command>
运行 yarn cache dir 会打印出当前的 yarn 全局缓存在哪里
改变 yarn 全局安装路径
设置安装位置
yarn config set global-folder <path>
yarn global bin 输出 yarn 为您已安装的可执行文件之符号链接准备的位置,打印存放全局 node_modules 的全局安装文件夹,可以使用 yarn config set prefix <filepath> 配置此基本位置。
例如设置 D:\Yarn\Global 为全局安装目录为例,则配置:
yarn config set global-folder D:\Yarn\Globalyarn config set prefix D:\Yarn\Global
管理工具
cgr
同时或分开管理 npm、yarn 源的工具,用来代替 nrm
- 安装
npm install -g cgr - 使用
- 默认源列表: N 代表 npm,Y 代表 yarn,* 代表 npm 和 yarn 共用的源
- 源切换: y/yarn 代表 yarn 切换,n/npm 代表 npm 切换,大小写均可,type 为空,表示同时切换源
- 添加私有源
cgr add 源name http[s]://xxx - 删除
cgr del 源 - 测试
cgr test
nrm
- 安装
npm install -g nrm - 查看所有配置的源
nrm ls - 切换源
nrm use <registry> - 添加源
nrm add registry http[s]://xxx - 删除源
nrm del <registry> - 测试响应速度
nrm test npm