npm的使用
npm init 初始化
npm install 包名 –g (uninstall,update)
npm install 包名 --save-dev (uninstall,update)
npm list -g (不加-g,列举当前目录下的安装包)
npm info 包名(详细信息) npm info 包名 version(获取最新版本)
npm install md5@1(安装指定版本)
npm outdated( 检查包是否已经过时)
npm set registry https://registry.npmmirror.com (修改npm仓库地址)
npm config delete registry (还原到原版仓库)
npm config get registry (查看当前仓库地址)
"dependencies": { "md5": "^2.1.0" } ^ 表示 如果 直接npm install 将会 安装 md5 2.*.* 最新版本
"dependencies": { "md5": "~2.1.0" } ~ 表示 如果 直接npm install 将会 安装 md5 2.1.* 最新版本
"dependencies": { "md5": "*" } * 表示 如果 直接npm install 将会 安装 md5 最新版本
nrm使用
NRM (npm registry manager)是npm的镜像源管理工具,有时候国外资源太慢,使用这个就可以
快速地在 npm 源间切换。
手动切换方法: npm config set registry https://registry.npm.taobao.org
终端全局安装nrm
npm i -g nrm
测试响应源的响应时间
nrm test
展示可用仓库
nrm ls
切换仓库
nrm use taobao
Registry has been set to: https://registry.npmmirror.com/
yarn使用
终端全局安装yarn
npm install -g yarn
对比
npm
:
速度超快: Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载。 同时利用并行下载以最大化
资源利用率,因此安装速度更快。
超级安全: 在执行代码之前,Yarn 会通过算法校验每个安装包的完整性。
开始新项目
yarn init
添加依赖包
yarn add [package]
yarn add [package]@[version]
yarn add [package] --dev
升级依赖包
yarn upgrade [package]@[version]
移除依赖包
yarn remove [package]
安装项目的全部依赖
yarn install