Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Yarn instead of Npm

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to use Yarn instead of Npm". In daily operation, I believe many people have doubts about how to use Yarn instead of Npm. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use Yarn instead of Npm"! Next, please follow the editor to study!

1. Introduction of Yarn

Yarn is a new JS package management tool jointly launched by Facebook, Google, Exponent and Tilde. As written in the official documentation, Yarn is designed to make up for some of the shortcomings of npm.

Second, Yarn advantages 1. High speed

The speed mainly comes from the following two aspects:

Parallel installation: both npm and Yarn perform a series of tasks when performing package installation. Npm executes each package by queue, which means that you must wait until the current package installation is complete before continuing with the subsequent installation. Yarn, on the other hand, performs all tasks simultaneously, improving performance.

Offline mode: if you have previously installed a software package, you will not have to download it from the network like npm if you get it from the cache when you install it again with Yarn.

2. Unified installation version

To prevent pulling to different versions, Yarn has a lock file (lock file) that records the version number of the module that is exactly installed. Each time a new module is added, Yarn creates (or updates) the yarn.lock file. This ensures that each time the same project dependency is pulled, the same module version is used. Npm actually has a way to use the same version of packages everywhere, but requires the developer to execute the npm shrinkwrap command. This command will generate a locked file, which will be read first when npm install is executed, just as Yarn reads the yarn.lock file. The difference between npm and Yarn is that Yarn generates such a locked file by default, while npm generates a npm-shrinkwrap.json file through the shrinkwrap command, and packages version information is recorded and updated only when this file exists.

3. More concise output

The output information of npm is lengthy. When you execute npm install, all installed dependencies are constantly printed on the command line. By contrast, Yarn is much more concise: by default, it combines emoji to print out the necessary information intuitively and directly, and provides commands for developers to query additional installation information.

4. Processing of multiple registered sources

All dependent packages, no matter how many times they are referenced indirectly by different libraries, are installed from only one registered source, either npm or bower, to prevent confusion and inconsistencies.

5. Better semantics

Yarn has changed the names of some npm commands, such as yarn add/remove, which feels clearer than npm's original install/uninstall.

Third, Yarn installs npm install-g yarn IV, Yarn command

1. View the version

Yarn-v

2. Create a project

Yarn init

3. Installation dependency

Yarn or yarn install

4. Run the script

Yarn run

5. Package construction

Yarn build

6. Display a package information

Yarn info

7. List the dependencies of the current project

Yarn list

8. Show the current configuration

Yarn config list

9. List each package that has been cached

Sudo yarn cache list

10. Clear the cache

Sudo yarn cache clean 5, NPM compare NpmYarnnpm installyarnnpm install react-- saveyarn add reactnpm uninstall react-- saveyarn remove reactnpm install react-- save-devyarn add react-- devnpm update-- saveyarn upgrade here, the study on "how to use Yarn instead of Npm" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report