npm / yarn / pnpm 本地配置

759 阅读1分钟

npm

打开本地npm文档(或npm install 文档)

npm help npm或npm help install     

展示command的用法

npm [command] -h    

展示所有command的用法

npm -l   

登录or注册

npm adduser   

查询所有npm相关的配置,调用npm config set进行更改或覆盖

npm config ls -l    

配置npm全局安装路径,添加Path '%NODE%\npm-global-modules'

npm config set prefix "D:\nodejs\npm-global-modules"    

配置npm缓存路径

npm config set cache "D:\nodejs\npm-cache"    

修改npm镜像(registry.npmjs.org/)(可以安装cnpm后修改cnpm的镜像)

npm config set registry "https://registry.npm.taobao.org/"   

配置成功后再次调用 npm config ls 查看

yarn

npm install -g yarn    # 全局安装yarn, 执行yarn help和yarn help [command]学习使用
yarn --version    # 检测yarn安装版本 1.22.x,在使用yarn init之前执行yarn set version berry, 版本就在此文件夹下变成2.x.x
yarn config list    # 查看yarn相关配置
yarn global bin    # yarn全局bin位置
yarn global dir    # yarn全局安装位置
yarn cache dir    # yarn全局缓存位置
yarn config set prefix "D:\nodejs\Yarn\Data\global"    # 配置yarn全局bin路径(D:\nodejs\Yarn\Data\global\bin) 添加Path '%NODE%\Yarn\Data\global\bin'
yarn config set global-folder "D:\nodejs\Yarn\Data\global"    # 配置yarn全局安装路径
yarn config set link-folder "D:\nodejs\Yarn\Data\link"    # 配置yarn全局link路径
yarn config set cache-folder "D:\nodejs\Yarn\Cache"    # 配置yarn全局缓存路径
yarn config set registry "https://registry.npm.taobao.org/"    # 修改yarn镜像(https://registry.yarnpkg.com)

pnpm

npm install -g pnpm    # 全局安装pnpm
pnpm --version    # pnpm版本
pnpm config set store-dir "D:.pnpm-store"    # pnpm全局仓库路径(类似 .git 仓库)
pnpm config set global-dir "D:\nodejs\pnpm\pnpm-global"    # pnpm全局安装路径
pnpm config set global-bin-dir "D:\nodejs"    # pnpm全局bin路径
pnpm config set state-dir "D:\nodejs\pnpm"    # pnpm创建pnpm-state.json文件的目录
pnpm config set cache-dir "D:\nodejs\pnpm\cache"    # pnpm全局缓存路径

参考文章