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 get GIT repository URL from source folder
There are several ways to get the link to a GIT repository from the directory... Read more
·1 min. read
Killing Floor monsters in Counter-Strike
Sorry, I don't IPs of these servers. 😳 Gorefast (XMAS) in Counter-Strike... Read more
·1 min. read
How to reinitialize multiple TinyMCE editors
At some point, there was a need to reload multiple TinyMCE editors on one page,... Read more
·1 min. read

© geekrainian.com