Skip to content

Instantly share code, notes, and snippets.

@mwilc0x
Last active January 23, 2017 23:02
Show Gist options
  • Save mwilc0x/493bf5038f272ea8ad10948cd4efb1c8 to your computer and use it in GitHub Desktop.
Save mwilc0x/493bf5038f272ea8ad10948cd4efb1c8 to your computer and use it in GitHub Desktop.
yarn info
Yarn is a package manager that wraps around the existing node package manager (npm).
The main advantages yarn offers are around the install process of node modules and how those are cached in a yarn.lock file.
If you have worked with node_modules before, you might be familiar with npm-shrinkwrap.json. Essentially think of yarn.lock
as a replacement for npm-shrinkwrap.json.
We recommend choosing yarn.lock over npm-shrinkwrap.json in production because it gives more reliable and deterministic builds.
To get started with yarn, you'll need to download it: https://yarnpkg.com/en/docs/install
The great thing about yarn is that it can be used alongside npm, you don't have to get rid of npm.
If you want to integrate yarn into an existing project workflow, simply run `yarn` from the root of the project where
the package.json file is. This will create a yarn.lock file. After this is created, you should remove npm-shrinkwrap.json
from git and add it to a .gitignore. Then, add yarn.lock to the repo, and commit it.
Yarn functions very similarly to npm, the commands for adding, removing, and upgrading are a little different
and you can find documentation on using these here https://yarnpkg.com/en/docs/managing-dependencies
Everytime you add, remove, or upgrade, the yarn.lock file will be updated. You should commit the updated yarn.lock file
anytime that you make a change.
Yarn is available on the Travis CI server, so you can run yarn installations there and use it in your CI workflow.
This should save some time on the build and give better accuracy for production builds as far as which packages are installed.
You don't have to use yarn for everything, you can still use npm to run scripts in your package.json folder, it's up to your
team to decide if they want to switch over to yarn completely for running scripts. The main thing it should be used for
is installations.
Yarn does a good job of not installing duplicate packages, but on your production server you may want to prune your
node_modules after a build to remove any dev dependencies. You can do that by running:
`yarn install --production --ignore-scripts --prefer-offline`
See https://github.com/yarnpkg/yarn/issues/696 for more information on this.
Also, keep in mind that yarn functions similarly to npm in that it will use your NODE_ENV and if it is production,
it will not install devDependencies. So keep that in mind when running installations.
Finally, if you want to learn more about yarn, the website has great docs: https://yarnpkg.com/en/docs/
This blog post details the motivations behind yarn: https://code.facebook.com/posts/1840075619545360
Also, this podcast gives some great insight into the why and how of yarn: https://www.youtube.com/watch?v=amaVRFsopZs
Happy Yarning!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment