Home Web Front-end JS Tutorial What is yarn? How does yarn manage front-end project module dependencies instead of npm?

What is yarn? How does yarn manage front-end project module dependencies instead of npm?

Sep 05, 2017 am 09:43 AM
yarn replace what is

This article mainly introduces you to the relevant information about using yarn instead of npm to manage front-end project module dependencies. The article introduces it in detail through sample code. It has certain reference learning value for everyone's study or work. Friends who need it Let’s learn together with the editor below.

This article mainly introduces to you the relevant content about yarn managing front-end project module dependencies instead of npm, and shares it for your reference and study. I won’t say much below, let’s take a look at the detailed introduction.

What is yarn?

# Simply put, yarn is a tool with the same function as npm, used for dependency management of front-end projects. In projects using npm, yran can be used instead wherever the npm command is used.

Why use yarn instead of npm? Compared with npm, the main features of yarn are:

  • Offline, parallel installation: dependencies are installed in parallel, downloaded dependencies are cached and used first, various optimizations make the installation of dependencies significantly faster To improve

  • Determinism: The yarn.lock file is generated by default, which can ensure that the directories used by developers to develop and install dependencies are consistent

  • more …

Well, in fact, npm is also constantly being optimized and improved. But yarn does have many highlights, and at least it is worth using for now.

Yarn Use Quick Start

Installation

Although you can install yarn without relying on npm, It is still recommended that you use npm to install it, fast and concise:


npm i -g yarn
Copy after login

Use

in the project when initializing the project for the first time Execution should also be executed before each project startup/build to ensure that local dependencies are updated in time.

This command will check the dependencies in the package.json and yarn.lock files. When their contents are updated, the dependencies will be updated and installed.


yarn <install>
Copy after login

Dependency update. Execute this command when you want to update dependent modules to their latest versions.


yarn upgrade
Copy after login

yarn Common commands

Start a new project


yarn init
Copy after login

Add dependent package


yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]
Copy after login

Upgrade dependent package


yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]
Copy after login

Remove dependent package


yarn remove [package]
Copy after login

Install all dependencies of the project


yarn
Copy after login

or


##

yarn install
Copy after login

Yarn usage practice suggestions

The main reason why we choose yarn is that the dependency installation speed is fast. The default generated yarn.lock will ensure that the module dependency directories of all members can be well consistent. .

The execution logic of yarn install and yarn upgrade allows you to clearly manage the version update timing of local dependencies, and can also keep the local dependencies of all developers consistent.

Using npm install is a bit messy. When you don’t want to hard-code version number dependencies, it will always install the latest available version of the dependent package, but sometimes this is not what you want.

Before yarn, we used the npm+Taobao warehouse solution, and also used cnpm. In China, cnpm's dependency installation speed is faster than yarn, but cnpm manages package dependencies by creating link references under windows, which may cause some problems.

Now we will use Taobao warehouse by default, use npm to manage global dependencies, and use yarn to manage dependencies within specific projects.

To use yarn in a new project, we will do this:

  • Write package.json and write the initial Three-party dependencies

  • Execute the yarn command to initialize the installation of project dependencies and generate the yarn.lock file

  • Add more requirements later by executing yarn add xxx Dependencies (can also be written directly in the package.json file)

  • When it is determined that the dependent module needs to be updated to its latest version, execute the yarn upgrade command

  • Before executing the configuration project startup command, execute the yarn command first to ensure that when yarn.lock is updated, local dependencies are also updated in time. For example, configure the start command in the script section of package.json: "start": "yarn && yarn run build:dev"

How do you use yarn? Feel free to share your experiences.

The above is the detailed content of What is yarn? How does yarn manage front-end project module dependencies instead of npm?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What kind of process is ccsvchst.exe? What kind of process is ccsvchst.exe? Feb 19, 2024 pm 11:33 PM

ccsvchst.exe is a common process file that is part of the Symantec Endpoint Protection (SEP) software, and SEP is an endpoint protection solution developed by the well-known network security company Symantec. As part of the software, ccsvchst.exe is responsible for managing and monitoring SEP-related processes. First, let’s take a look at SymantecEndpointProtection(

JavaScript package managers compared: Npm vs Yarn vs Pnpm JavaScript package managers compared: Npm vs Yarn vs Pnpm Aug 09, 2022 pm 04:22 PM

This article will take you through the three JavaScript package managers (npm, yarn, pnpm), compare these three package managers, and talk about the differences and relationships between npm, yarn, and pnpm. I hope it will be helpful to everyone. Please help, if you have any questions please point them out!

An article briefly analyzing the JS package management tool: yarn An article briefly analyzing the JS package management tool: yarn Aug 09, 2022 pm 03:49 PM

Yarn, like npm, is also a JavaScript package management tool. In this article, I will introduce you to the yarn package management tool. I hope it will be helpful to you!

What is a dual-core browser? What is a dual-core browser? Feb 20, 2024 am 08:22 AM

Dual-core browser is a browser software that integrates two different browser cores. The kernel is the core part of the browser, responsible for rendering web content and executing web scripts and other functions. Traditional browsers generally use only a single kernel, such as IE browser using Trident kernel, Chrome browser using WebKit/Blink kernel, Firefox browser using Gecko kernel, etc. The dual-core browser integrates two different cores into one browser, and users can freely switch between them as needed. The emergence of dual-core browsers

What is a CPU? What does a CPU contain? What is a CPU? What does a CPU contain? Feb 22, 2024 pm 05:55 PM

cpu is the central processing unit. Analysis 1 The central processing unit [CPU, Central Processing Unit] is a very large-scale integrated circuit, which is the computing core and control core of a computer. Its main function is to interpret computer instructions and process data information in computer software. Supplement: What does the CPU include? 1 The CPU includes computational thinking components, register components, control components, etc. The computational thinking component can perform specified address or floating-point arithmetic operations, shift operations and thinking operations, and can also perform address calculations and conversions. Summary/Notes CPU mainly explains computer instructions and processes data information in computer software.

What is ALICE coin? What is ALICE coin? Feb 23, 2024 am 09:28 AM

What is ALICE coin? ALICE coin is a digital cryptocurrency inspired by the English word "ALICE", which symbolizes the unique creativity and imagination of the creator. As a virtual currency based on blockchain technology, ALICE currency aims to provide users with a safe, convenient and privacy-protected transaction environment. Application of Blockchain Technology In order to achieve the recording and verification of transactions, ALICE currency uses blockchain technology. Blockchain is a distributed database that links transaction information together in chronological order to form an immutable chain. This technology greatly improves the security of transaction information, while also eliminating the need for trust in third-party institutions and reducing transaction costs. Due to the decentralized nature of blockchain, transaction participants can

What is WEB coin Webchain? What is WEB coin Webchain? Feb 21, 2024 pm 06:28 PM

What are Webcoin and Webchain? Webcoin and Webchain are two closely related cryptocurrency projects that aim to provide global users with a secure and anonymous digital currency trading experience. Webcoin is a cryptocurrency based on blockchain technology, and Webchain is the underlying blockchain platform that supports the operation of Webcoin. The combination of these two projects enables users to conduct efficient and secure digital currency transactions with guaranteed anonymity. WebcoinWebcoin is a decentralized digital currency using blockchain technology, aiming to provide a safe and efficient trading environment for global users. Its open source design makes transaction recording and verification more transparent and reliable. W

What should I do if the react installation yarn keeps reporting that it is not an internal command? What should I do if the react installation yarn keeps reporting that it is not an internal command? Jan 04, 2023 am 09:24 AM

The solution to the problem that the react installation yarn keeps reporting that it is not an internal command: 1. Uninstall yarn through the command "pm uninstall yarn -g"; 2. Reinstall yarn using "npm install yarn"; 3. Add "C:\ WINDOWS\system32\node_modules\yarn\bin"; 4. Re-open cmd and execute the "yarn -v" command.

See all articles