Yarn’s link functionality is really useful when developing a package and wanting to use it in your application whilst the package is in development.
Let’s assume you’ve created a package, for the sake of having an example, let’s assume it’s a cool new radio button control. You’ve created it and pushed to npm and all’s great but then you want to make some changes.
You don’t want to make those changes and push them to npm so that you can test them, yes you could take the code from the package etc. or use Yalc.
Or we can use yarn link.
In the package you’re editing, simply run
yarn link
this will result in the following command being available to run in the application using the package
yarn link "@namespace/package-name"
Note: obviously remove the namespace if non is used and replace package-name with the name of the package to link.
After you execute the above command and if you’re using Visual Code’s look at the explorer window, in the node_modules of the application using the package you’ll find the @namespace/package-name with a little symbolic link icon.
If you wish to unlink then, from your application use
yarn unlink "@namespace/package-name"
and from the package itself
yarn ulink