npm,cnpm,yarn这三个或许使用Hexo,Hugo,vuepress等静态博客搭建的小伙伴们来说,会经常遇见,会使用它们进行插件,依赖包等的安装、卸载与更新,如果你是前端开发者或者是准备从事前端的话,你会经常与它们三个打交道,下面简单的说说它们三剑客吧!
npm是什么?
npm 为你和你的团队打开了连接整个 JavaScript 天才世界的一扇大门。它是世界上最大的软件注册表,每星期大约有 30 亿次的下载量,包含超过 600000 个 包(package) (即,代码模块)。来自各大洲的开源软件开发者使用 npm 互相分享和借鉴。包的结构使您能够轻松跟踪依赖项和版本。引自npm中文网
npm (node package manager)是 JavaScript 世界的包管理工具,是 Node.js 平台的默认包管理工具,是前端模块化下的一个标志性产物,简单地说,就是通过npm下载模块,复用已有的代码,提高工作效率。
下面是关于 npm 的快速介绍:
npm 由三个独立的部分组成:
-
网站
-
注册表(registry)
-
命令行工具 (CLI)
网站 是开发者查找包(package)、设置参数以及管理 npm 使用体验的主要途径。
注册表 是一个巨大的数据库,保存了每个包(package)的信息。
CLI 通过命令行或终端运行。开发者通过 CLI 与 npm 打交道。
npm常用命令
- 查看npm的版本
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n23" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm -v #npm -version</pre>
- 查看npm帮助
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n27" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"># 查看所有的命令帮助
npm help
如果要单独查看install命令的帮助,可以使用下面的命令
npm help install</pre>
- 查看安装过的所有包
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n31" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm list #列出当前安装过的所有包
或者简写
npm ls
npm ls -g #查看全局安装的模块及依赖 </pre>
- 本地安装依赖包和全局安装(global)
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n35" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">#安装nodejs的依赖包,默认安装最新版本(本地)
npm install <Package name>
一次性安装多个(本地)
npm install 模块名 模块名
安装指定版本号的依赖包(本地)
npm install <Package name>@version
将包安装到全局环境中
npm install <Package name> -g
根据package.json文件安装
npm install</pre>
- 卸载依赖包
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n39" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm uninstall <Package name>
npm uninstall gulp --save-dev #卸载开发版本的模块</pre>
- 安装生产阶段的依赖包
-S, - -save 安装包信息将加入到dependencies(生产阶段的依赖)
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n45" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm install gulp --save 或 npm install gulp -S</pre>
package.json
文件的 dependencies
字段:
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="json" cid="n47" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"dependencies": {
"gulp": "^4.0.2"
}</pre>
- 安装开发阶段的依赖包
-D, --save-dev 安装包信息将加入到devDependencies(开发阶段的依赖),所以开发阶段一般使用它
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n53" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm install gulp --save-dev 或 npm install gulp -D</pre>
package.json
文件的devDependencies
字段:
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="json" cid="n55" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"devDependencies": {
"gulp": "^4.0.2"
}</pre>
- 安装可选阶段的依赖包
-O, --save-optional 安装包信息将加入到optionalDependencies(可选阶段的依赖)
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n61" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm install gulp --save-optional 或 npm install gulp -O</pre>
package.json
文件的optionalDependencies
字段:
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="json" cid="n63" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"optionalDependencies": {
"gulp": "^4.0.2"
}</pre>
- 精确安装指定版本依赖包
-E, --save-exact 精确安装指定模块版本
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n69" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm install gulp --save-exact 或 npm install gulp -E</pre>
输入命令npm install gulp -ES
,留意package.json
文件的 dependencies
字段,以看出版本号中的^**消失了。
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="json" cid="n71" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">"dependencies": {
"gulp": "4.0.2"
}</pre>
模块的依赖都被写入了package.json
文件后,他人打开项目的根目录(项目开源、内部团队合作),使用npm install
命令可以根据dependencies
配置安装所有的依赖包。
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n73" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm install</pre>
image注意:
npm 的package.json中的~和^
-
~ 会匹配最近的小版本依赖包,比如~1.2.3会匹配所有1.2.x版本,但是不包括1.3.0
-
^ 会匹配最新的大版本依赖包,比如^1.2.3会匹配所有1.x.x的包,包括1.3.0,但是不包括2.0.0
- 更新依赖包
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n85" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm update <Package name></pre>
- 检查哪些依赖包是否过时
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n89" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm outdated</pre>
执行上面的命令,会出现如下情况:
image另外有个检查依赖包更强大的一个第三方工具 npm-check,具体使用方法,请查看它的文档。
- 查看和管理
npm
的基础配置
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n96" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm config list -l #查看所有的配置</pre>
- 清除本地
npm cache
缓存
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n100" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm cache clean</pre>
- 初始化项目
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n104" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm init #初始化项目,并在项目文件夹中引导创建一个package.json文件</pre>
其他npm命令可以看NPM中文文档
cnpm是什么?
简单的讲就是中国版的NPM,因为npm安装插件是从国外服务器下载,受网络影响大,可能出现异常,所以我们乐于分享的淘宝团队干了这事。
这是一个完整
npmjs.org
镜像,你可以用此代替官方版本(只读),同步频率目前为 10分钟 一次以保证尽量与官方服务同步。—来自淘宝 NPM 镜像
如何使用cnpm?
首先就是需要安装cnpm
模块,命令如下:
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n112" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm install -g cnpm --registry=https://registry.npm.taobao.org</pre>
cnpm
支持可以使用支持npm
除publish
之外的所有命令。
因为cnpm
的仓库只是 npm
仓库的一个拷贝,它不承担 publish
工作,所以执行cnpm publish
命令会失败的。
yarn是什么?
yarn是个包管理器。你可以通过它使用全世界开发者的代码, 或者分享自己的代码。
从 npm
安装软件包并保持相同的包管理流程。
- 特点:
- 速度超快。
Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载。 同时利用并行下载以最大化资源利用率,因此安装速度更快。
- 超级安全
在执行代码之前,Yarn 会通过算法校验每个安装包的完整性。
- 超级可靠
使用详细、简洁的锁文件格式和明确的安装算法,Yarn 能够保证在不同系统上无差异的工作。
- 安装
- 通过命令安装
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n139" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Cousine, Consolas, monospace; font-size: 14px; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(30, 32, 34); position: relative !important; width: auto; color: rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">npm install -g yarn</pre>
查看版本:yarn --version
- 通过安装包程序安装
地址:https://classic.yarnpkg.com/zh-Hans/docs/install#windows-stable
- 常用命令:
-
yarn init
:初始化项目,会在根目录下生成一个package.json
,与npm
类似具体不做解释 -
yarn add <Package name>
:安装依赖包,会自动安装最新版本,会覆盖指定版本号 -
yarn add <Package name1> <Package name1>
:一次性添加多个包 -
yarn add <Package name>@version
:添加指定版本的包 -
yarn upgrade <Package name>@version
:将包更新到指定版本 -
yarn upgrade --latest <Package name>
:将包更新到最新版本 -
yarn remove <Package name>
:删除包 -
yarn remove <Package name1> <Package name2>
:一次性删除多个包 -
yarn info <Packagename>
:可以用来查看某个模块的最新版本信息 -
yarn install
:安装package.json
里所有包,并将包及它的所有依赖项保存进yarn.lock
-
yarn install --force
:强制重新下载所有包 -
yarn install --flat
:安装一个包的单一版本 -
yarn install --production
:只安装dependencies
里的包 -
yarn install --no-lockfile
:不读取或生成yarn.lock
-
yarn install --pure-lockfile
:不生成yarn.lock
具体详细的命令可以查看官方文档:https://classic.yarnpkg.com/zh-Hans/docs
网友评论