npm install yarn --global
# or you can install yarn via brew on macOS
brew install yarn
yarn init
Install dependencies
npm install vs yarn install
Yarn gets the job done much faster
Yarn caches dependencies locally, hence they're available offline!
Dependency version management
npm install --save express@4.0.0 vs yarn add express@4.0.0
generates
"express": "^4.0.0" vs "express": "4.0.0"
^ is dangerous, it allows your dependency to be updated (the feature, and patch release updates) next time you run npm install
Yarn generates the yarn.lock file when installing dependencies, to ensure dependencies consistency. Which is similar to the npm-shrinkwrap.json file generated by npm shrinkwrap, but instead of running the shrinkwrap command every time, yarn keeps it updated automatically.
right, no need for --save when doing yarn add
Remove dependency
npm uninstall express --save vs yarn remove express
Install dev dependency
npm install gulp --save-dev vs yarn add gulp --dev
Yarn tips and tricks
# to list all yarn global caches
yarn cache ls
# to install bower dependencies, yes, you can
yarn install
# to find out why certain dependency exists
yarn why gulp
Getting started with Yarn
Install dependencies
npm install
vsyarn install
Dependency version management
npm install --save express@4.0.0
vsyarn add express@4.0.0
generates
"express": "^4.0.0"
vs"express": "4.0.0"
^
is dangerous, it allows your dependency to be updated (the feature, and patch release updates) next time you runnpm install
yarn.lock
file when installing dependencies, to ensure dependencies consistency. Which is similar to thenpm-shrinkwrap.json
file generated bynpm shrinkwrap
, but instead of running the shrinkwrap command every time, yarn keeps it updated automatically.--save
when doingyarn add
Remove dependency
npm uninstall express --save
vsyarn remove express
Install dev dependency
npm install gulp --save-dev
vsyarn add gulp --dev
Yarn tips and tricks