cheatsheets/yarn.md

98 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2016-10-12 05:58:02 +02:00
---
title: Yarn
category: JavaScript libraries
2017-08-29 19:48:29 +02:00
weight: -3
2020-07-04 15:33:09 +02:00
updated: 2019-09-30
2017-09-08 08:04:42 +02:00
prism_languages: [json, bash]
tags: [Featurable]
2016-10-12 05:58:02 +02:00
---
2017-08-29 19:48:29 +02:00
### npm equivalents
2016-10-12 05:58:02 +02:00
| npm | yarn |
| --- | ---- |
2019-09-30 15:08:39 +02:00
| `npm init` | `yarn init` |
2016-10-12 05:58:02 +02:00
| `npm install` | `yarn` |
2016-10-16 17:49:05 +02:00
| `npm install gulp --save` | `yarn add gulp` |
2016-10-12 05:58:02 +02:00
| `npm install gulp --save-dev --save-exact` | `yarn add gulp --dev --exact` |
| `npm install -g gulp` | `yarn global add gulp` |
| `npm update` | `yarn upgrade` |
2016-10-12 05:58:02 +02:00
| `./node_modules/.bin/gulp` | `yarn run gulp` |
2017-08-29 19:48:29 +02:00
{: .-left-align.-headers}
2016-10-12 05:58:02 +02:00
2018-04-07 12:38:56 +02:00
### yarn install
```
--no-lockfile
--pure-lockfile
--frozen-lockfile
--silent
--offline
--update-checksums
--check-files
--flat
--force
--ignore-scripts
--modules-folder <path>
--production[=true|false]
```
These options are available for `yarn install`.
2017-08-29 19:48:29 +02:00
### yarn add
2016-10-12 05:58:02 +02:00
```
--dev
--peer
--optional
--exact
--tilde
```
2017-08-29 19:48:29 +02:00
These options are available for `yarn add`.
2017-09-08 07:56:55 +02:00
### Workspaces
2017-09-08 08:04:42 +02:00
In `package.json`:
{: .-setup}
2017-09-08 07:56:55 +02:00
```json
"workspaces": [
"packages/*"
]
```
```
jest/
├─ package.json
└─ packages/
├─ jest-matcher-utils/
│ └─ package.json
└─ jest-diff/
└─ package.json
```
2017-09-08 08:04:42 +02:00
{: .-box-chars}
2017-09-08 07:56:55 +02:00
(New in 1.0) Allows monorepos to share packages with each other. See: [Introducing workspaces](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/)
### Selective version resolution
2017-09-08 08:04:42 +02:00
In `package.json`:
{: .-setup}
2017-09-08 07:56:55 +02:00
```json
"resolutions": {
"**/sass-brunch/node-sass": "4.5.2"
}
```
(New in 1.0) Allows you to specify versions for sub-dependencies. See: [Selective version resolutions](https://github.com/yarnpkg/yarn/pull/4105)
2017-09-08 08:00:24 +02:00
### Create
```bash
yarn create react-app hello
```
Install `create-react-app` and runs it. See: [yarn create](https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-yarn-create.md)