第三章 NPM安装yarn

安装yarn的前提是需要先安装好npm,且环境变量都配置好了,才可以使用。

一、下载安装

# 1.安装yarn
[root@VM-0-15-centos ~]# npm install yarn -g
added 1 package in 1s

# 2.检查版本
[root@VM-0-15-centos ~]# yarn --version
1.22.19

二、配置Yarn

# 1.配置源
[root@VM-0-15-centos ~]# yarn config set registry https://registry.npm.taobao.org -g
[root@VM-0-15-centos ~]# yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ -g

# 2.检查源
[root@VM-0-15-centos ~]# yarn config get registry
https://registry.npm.taobao.org
[root@VM-0-15-centos ~]# yarn config get sass_binary_site
https://npm.taobao.org/mirrors/node-sass/

三、Yarn的优点

yarn是Facebook发布的一款npm包管理工具,个人感觉使用起来非常舒服:

# 1.安全
在执行代码之前,Yarn会通过算法校验每个安装包的完整性。

# 2.速度快
Yarn缓存了每个下载过的包,所以再次使用时无需重复下载。 同时利用并行下载以最大化资源利用率,因此安装速度更快。

# 3.可靠
由于yarn.lock存在的机制,项目中的依赖的版本会被锁定,不用担心协同开发过程中出现版本不一致的问题。而npm永远都会给你下载最新的依赖版本,非常的狗血。

四、一些常用的Yarn命令

yarn init // 生成package.json文件
yarn install // 安装yarn.lock的所有依赖
yarn install --force // 重新安装依赖
yarn remove moduleName // 删除依赖
yarn add moduleName // 安装某个依赖
yarn add moduleName --dev/-D // 安装到开发环境
yarn run scriptName // 执行package.json命名的脚本命令
posted @ 2022-10-20 10:48  年少纵马且长歌  阅读(879)  评论(0编辑  收藏  举报