Yarn commands cheatsheet

·2 min. read·

In this article, I will describe the basic Yarn commands and their usage, using the popular lodash package as an example.

To find out why it's better to use Yarn instead of NPM, please read this article where I compared these tools.

Install the latest version of the package:

yarn add lodash@latest

Install the latest version of the package and save to devDependencies instead of dependencies:

yarn add -D lodash@latest

Install the latest version of the package globally:

yarn add global lodash@latest

Install specific version of the package (eg 3.10.1):

Install caret version of the package (eg ^4.13.1).

When a caret version of a package is specified, it sets certain rules for updating the dependency when installing new package versions. In this case, "^4.13.1" means that Yarn can install any minor or patch version that is compatible with version 4.13.1 but should not exceed major version 5.

yarn add lodash@^4.13.1

Hint: use NPM repositories to browse the list of versions for your package. For example: lodash.

Uninstall the package:

yarn remove lodash

Uninstall the globally installed package:

yarn global remove lodash

The command `yarn set version`` allows you to switch the Yarn version at the project level.

Activate the latest stable version (4.x at the time of writing this article):

yarn set version stable

Activate the latest 3.x version:

yarn set version 3.x

Activate classic (old) 1.x version:

yarn set version classic

You may also like

How to enable HTTPS on localhost for Node.js
Sometimes, you may need to secure your localhost to test certain things, such... Read more
·2 min. read
How to connect Namecheap domain to A2Hosting VPS
Go to the A2Hosting admin panel and open your product "VPS Hosting". Look for... Read more
·1 min. read
Killing Floor monsters in Counter-Strike
Sorry, I don't have IPs of these servers. 😳 Gorefast (XMAS) in Counter-Strike... Read more
·1 min. read

© geekrainian.com