npm安装:
局部安装:
生产环境依赖dependencies(两个环境都可以用):
- npm install xxxx --save
- 或 npm i xxxx -S
- 或
npm i xxxx
开发环境依赖devDependencies:
- npm install xxxx --save-dev
npm i xxxx -D
全局安装:
npm root -g
即可查看安装在C盘的路径带有指令集的包要进行全局安装(指令到处可用)
-
npm i xxxx -g@yyy : 安装xxx包的yyy版本
-
npm i
:安装package.json中所有包
移除:
npm remove xxxx
在node_module中和packxxxxage.json中删除包x’x’x’x
其他命令:
- npm aduit fix :检测项目依赖中的一些问题,并且尝试着修复
npm view xxxx versions
:查看远程npm仓库中xxxx包的所有版本信息- npm view xxxx version :查看npm仓库中xxxx包的最新版本
- npm ls xxxx :查看我们所安装的xxxx包的版本
包的版本:
- “
^3.x.x
”:锁定大版本,以后安装包的时候,保证包是3.x.x版本,x是默认取最新的(默认) - “
~3.1.x
”:锁定小版本,以后安装包的时候,保证包是3.1.x版本,x默认取最新的 - “
3.1.x
”:锁定完整,以后安装包的时候,保证必须是3.1.x版本
cnpm的使用:
第一种:直接安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
第二种:替换npm仓库地址为淘宝镜像地址(推荐)
npm config set --registry=https://registry.npm.taobao.org
- 查看是否更改成功:npm config get registry
yarn的使用:
-
全局安装
npm install yarn -g
-
安装yarn后分别执行
yarn global dir
命令,yarn global bin
命令将上述两部返回的路径配置到电脑环境变量中即可
下载
yarn global add xxxx
- 上面默认下载生产依赖,加上-D为开发依赖,加上@为指定版本
删除
yarn remove xxxx
- yarn global remove xxxx
设置淘宝镜像
yarn config set --registry=https://registry.npm.taobao.org
- 查看是否配置淘宝镜像:yarn config get registry
查看某个包信息
- yarn info xxx