Front-end must understand the differences and commonalities of npm yarn

Some differences between package management tools npm and yarn
1. Official website documentation
[npm](https://www.npmjs.cn/)
[yarn](https://yarn.bootcss.com/)
1
2
2. The existence of npm Some problems
are extremely slow when using npm install. Especially when pulling down a new project, I have to wait for half a day, delete node_modules, and it still remains the same when reinstalling.

The same project cannot be consistent during installation. Due to the characteristics of the version number in the package.json file, the following three version numbers represent different meanings during installation. "5.0.3" means to install the specified version 5.0.3, "~5.0.3" means to install the latest version in 5.0.X, and "^5.0.3" means to install the latest version in 5.XX. This is troublesome. It often happens that for the same project, some colleagues are OK, but some colleagues will have bugs due to inconsistent installed versions.

"5.0.3",
"~5.0.3",
"^5.0.3"
1
2
3
When installing, the package will be downloaded and installed at the same time. Sometime in the middle, a package throws an error, but npm Downloading and installing the package will continue. Because npm outputs all logs to the terminal, error information about the wrong package will be lost in the pile of warnings npm prints, and you will never even notice the actual error that occurred.
3. What is Yarn? What are the advantages
? "Yarn is a new JS package management tool jointly launched by Facebook, Google, Exponent and Tilde. It appears to make up for some of the shortcomings of npm.
Its advantages:

The installation speed is fast (the server speed is fast, and it is downloaded in parallel).
The version is locked and the installation version is unified with
a caching mechanism. If a software package has been installed before, it will be obtained from the cache when installing it again with Yarn. There is no need to re-install it from the cache like npm. Downloaded from the Internet
4. Comparison of common commands
npm yarn
npm install yarn
npm install module name--save-dev yarn add module name--dev
npm install module name--save yarn add module name
npm run serve yarn serve
npm run build yarn build
5. Others
– Set Taobao mirror
'NPM queries the currently configured mirror'
npm get registry
'Set NPM to Taobao mirror'
npm config set registry https://registry.npm.taobao.org

'Yarn queries the currently configured image'
yarn config get registry
'Yarn is set to Taobao image'
yarn config set registry https://registry.npm.taobao.org
 

Guess you like

Origin blog.csdn.net/lyinshaofeng/article/details/128248931