


What is yarn? How does yarn manage front-end project module dependencies instead of npm?
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
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>
Dependency update. Execute this command when you want to update dependent modules to their latest versions.
yarn upgrade
yarn Common commands
Start a new project
yarn init
Add dependent package
yarn add [package] yarn add [package]@[version] yarn add [package]@[tag]
Upgrade dependent package
yarn upgrade [package] yarn upgrade [package]@[version] yarn upgrade [package]@[tag]
Remove dependent package
yarn remove [package]
Install all dependencies of the project
yarn
or
##
yarn install
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"
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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(

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!

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!

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

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? 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 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

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.
