一、npm与yarn介绍
二、常用使用方法
说明 |
NPM |
YARN |
初始化 |
npm init |
yarn init |
默认安装依赖 |
npm install xxx |
yarn install xxx |
安装某个依赖并保存 |
npm install xxxx -save |
yarn add xxxx |
安装全局依赖 |
npm install -g xxxx |
yarn global add xxxx |
移除依赖 |
npm uninstall xxxx -save |
yarn remove xxxx |
更新依赖 |
npm update |
yarn upgrade xxxx |
运行指令 |
npm run |
yarn run |
三、npm相关配置
npm config list # 查看配置
npm config set cache/prefix/... "xxx" # 配置
npm config get cache/prefix/... # 查看某一项配置
npm config delete cache/prefix/... # 删除某一项配置
# 安装与卸载
npm install xxx -g # 全局安装xxx
npm uninstall xxx -g # 全局卸载xxx
npm install --save xxx # 写入package.json中的dependencies选项中
npm install --save-dev xxx # 写入package.json中的devDependencies选项中
npm uninstall --save xxx # 从dependencies中删除
npm uninstall --save-dev xxx # 从devDependencies中删除
npm cache clean -f # 清理缓存
npm --registry https://registry.npm.taobao.org install express
npm config set registry https://registry.npm.taobao.org
npm config set prefix "~/node_modules/node_global"
npm config set cache "~/node_modules/node_cache"
xxx@Amio ~ npm install -g npm
/Users/xxx/node_modules/node_global/bin/npm -> /Users/xxx/node_modules/node_global/lib/node_modules/npm/bin/npm-cli.js
/Users/xxx/node_modules/node_global/bin/npx -> /Users/xxx/node_modules/node_global/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.14.8
added 434 packages from 885 contributors in 9.322s