Bring together the 2022 Total-Stack Spider web Dev Bootcamp!


  • Intro to Yarn
  • Install Yarn
  • Managing packages
    • Initialize a new projection
    • Install the dependencies of an existing project
    • Install a parcel locally
    • Install a package globally
    • Install a package locally equally a development dependency
    • Remove a packet
  • Inspecting licenses
  • Inspecting dependencies
  • Upgrading packages
  • How to upgrade Yarn

Intro to Yarn

Yarn is a JavaScript Package Manager, a directly competitor of npm, and information technology's one of the Facebook Open Source projects.

It'southward compatible with npm packages, and so it has the great advantage of being a driblet-in replacement for npm.

When information technology launched it used to be way faster than npm due to parallel download and caching, but now npm did catch upwardly with many of its features and is at present the solution I recommend.

Tools somewhen converge to a prepare of features that keeps them on the aforementioned level to stay relevant, so we'll likely see those features in npm in the future - competition is nice for us users.

Install Yarn

While y'all can install Yarn with npm (npm install -g yarn), it'southward not recommended by the Yarn team.

System-specific installation methods are listed at https://yarnpkg.com/en/docs/install. On macOS for example y'all can use Homebrew and run

only every Operating System has its own package manager of choice that will make the process very smooth.

In the end, you'll stop up with the yarn command bachelor in your beat:

Yarn command installed

Managing packages

Yarn writes its dependencies to a file named parcel.json, which sits in the root folder of your project, and stores the dependencies files into the node_modules folder, but like npm if you used it in the past.

Initialize a new projection

starts an interactive prompt that helps you lot quick start a project:

Running yarn init

Install the dependencies of an existing project

If you lot already have a bundle.json file with the list of dependencies simply the packages accept not been installed even so, run

or

to start the installation process.

Install a package locally

Installing a package into a project is done using

Install a package globally

            yarn global add package-proper noun          

Install a package locally every bit a evolution dependency

            yarn add --dev parcel-proper noun          

Equivalent to the --relieve-dev flag in npm

Remove a packet

Inspecting licenses

When installing many dependencies, which in plow might take lots of dependencies, you install a number of packages, of which you don't have any idea most the license they use.

Yarn provides a handy tool that prints the license of any dependency you take:

The yarn packages licenses visualized

and it tin can as well generate a disclaimer automatically including all the licenses of the projects you use:

            yarn licenses generate-disclaimer          

Disclaimer generated by yarn

Inspecting dependencies

Do yous ever check the node_modules folder and wonder why a specific package was installed? yarn why tells you:

The result of yarn why

Upgrading packages

If you want to upgrade a unmarried package, run

            yarn upgrade parcel-name          

To upgrade all your packages, run

But this command can sometimes atomic number 82 to bug, because you lot're blindly upgrading all the dependencies without worrying about major version changes.

Yarn has a not bad tool to selectively update packages in your project, which is a huge aid for this scenario:

Upgrading packages with yarn

How to upgrade Yarn

At the fourth dimension of writing there is no motorcar-update command.

If you used brew to install it, similar suggested to a higher place, use:

If instead you installed using npm, use:

            npm uninstall yarn -g npm install yarn -g