Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm和yarn常用命令合集 #78

Open
LightXJ opened this issue Apr 14, 2021 · 0 comments
Open

npm和yarn常用命令合集 #78

LightXJ opened this issue Apr 14, 2021 · 0 comments

Comments

@LightXJ
Copy link
Owner

LightXJ commented Apr 14, 2021

查看版本

npm -v
yarn -v

查看依赖

yarn list  查看本地依赖
yarn list --depth=0  查看本地依赖,深度为0
yarn list --pattern gulp 筛选出依赖
yarn global list 列出全局安装的依赖

npm ls       查看本地依赖
npm ls -g    查看全局依赖
npm ls —depth  查看本地依赖,深度为0

查看安装路径

查看全局安装路径
yarn global dir   
npm config get prefix

查看本地安装路径
npm root

查看依赖包信息

yarn info react   展示依赖包信息,注意,这时依赖包并没有被安装在本地
npm info react

yarn list --depth=0 查看安装过的依赖包和版本
npm ls --depth=0 查看安装过的本地依赖版本

管理配置文件

查看配置key的值
yarn config list 查看当前的配置【yarn没有全局配置】
yarn config get <key>  
yarn config delete <key> 
yarn config set <key> <value>

通过配置文件
.npmrc文件,对应npm
 registry=http://registry.npm.taobao.org/

.yarnrc文件,对应yarn
registry http://registry.npm.taobao.org/

查询镜像[镜像不分本地和全局]

npm config get registry
yarn config get registry

设置镜像[镜像不分本地和全局]

npm config set registry http://registry.npm.taobao.org/
yarn config set registry http://registry.npm.taobao.org/

安装

#### 全局安装
npm install -g webpack
yarn global add webpack

#### 生产环境 dependencies
npm install webpack
yarn add webpack

#### 开发环境 devDependencies
npm install webpack --dev
yarn add webpack --dev

删除

删除全局安装的包
npm uninstall -g webpack
yarn global remove webpack

删除本地安装的包【会更新到package.json】
npm uninstall webpack
yarn uninstall webpack

全局yarn

和 npm 在全局安装操作时需要使用 -g 或者 --global 标志不同,Yarn 命令需要用 global 作为前缀。和 npm 一样,具体项目的依赖性不应该全局安装。
global 前缀仅适用于 yarn add,yarn bin,yarn list 和 yarn remove、upgrade、upgrade-interactive。除了 yarn add,这些命令都和 npm 命令一样。

npm和yarn设置镜像会冲突吗

不会,用什么工具就用哪个配置的镜像

快捷管理镜像

用nrm快速管理npm的镜像,不过不太必要,毕竟切换源不是很高频的操作

yarn和npm的区别

https://juejin.cn/post/6844903582903320589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant