In addition to npm, there is this package management tool

Speaking of package management tools, npm is the most familiar to everyone. In addition to it, there is yarn. I believe you must have heard of it. Next, let's take a look at what yarn is and how to use it.

1. What is yarn?

Yarn is a package manager for your code. It allows you to use and share (such as JavaScript) code from developers all over the world. Yarn can complete these tasks quickly, safely, and reliably, so you don't have to worry about it.

Through Yarn, you can use other developers' solutions to different problems to make your own development process easier. If you encounter problems during use, you can report them or contribute solutions. Once the problem is fixed, Yarn will update to keep in sync.

Code is shared through  packages (  or  modules) . A package contains all the code that needs to be shared, as well as the file describing the package information, called  package.json .

2. Installation

There are three ways to install Yarn on windows system,

2.1 Download the installer

Download an  .msi installation file, and when it runs, it will guide you to install Yarn on Windows.

If you use this installer, you need to install Node.js first  .

2.2 Install via Chocolatey

Chocolatey  is a Windows-specific package management tool. Follow these  instructions to  install Chocolatey.

After installing Chocolatey, you can install Yarn by executing the following command on the console:

choco install yarn

2.3 Installation via Scoop

Scoop  is a command-line-based installation tool for Windows. Follow this  instruction to  install Scoop.

After Scoop is installed, you can install Yarn by executing the following commands on the console:

scoop install yarn

 If  Node.js  is not installed, scoop will prompt you to install it. E.g:

scoop install nodejs

 

After installation, you can check whether the installation is successful through the following command:

yarn --version

3. How to use

3.1 Initialize the project

yarn init

3.2 Add dependency

yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

3.3 Adding dependencies to different dependency categories

Add to  devDependencies, peerDependencies and  categories respectively: optionalDependencies

yarn add [package] --dev
yarn add [package] --peer
yarn add [package] --optional

3.4 Upgrade dependent packages

yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

3.5 Install all the dependencies of the project, you can directly yarn

yarn

or

yarn install

 

Guess you like

Origin blog.csdn.net/RedaTao/article/details/109233014