npm、yarn命令

前端 0 485 0
发表于: 2020-02-21 17:50:14

简介: 不常用但重要,要找的时候太烦了

查看 npm 全局安装过的包

npm list -g --depth=0

查看 yarn 全局安装过的包

yarn global list --depth=0

yarn 装包

yarn add vue
yarn remove vue
yarn global remove vue

npm 装包

npm i vue
npm uninstall vue
npm remove vue -g

npm 和 yarn 缓存

npm:

# 查看缓存目录
npm config get cache
# 清除缓存
npm cache clean --force
# 设置缓存目录
npm config set cache "F:\ProgramFile\nodejs\node_module\node_cache"
# 验证缓存文件夹的内容, 删除不需要的, 并验证缓存索引和所有缓存数据的完整性
npm cache verify

yarn:

# 查看缓存目录
yarn cache dir
# 运行命令会清理缓存包,若未指定包名则会全部清理,指定则清理指定包。
yarn cache clean [<module_name...>]
# 设置缓存目录,注意要先清理包在重新配置目录,否则会使之前的缓存无法清除
yarn config set cache-folder