OSDN Git Service

Regular updates
[twpd/master.git] / yarn.md
1 ---
2 title: Yarn
3 category: JavaScript libraries
4 layout: 2017/sheet
5 weight: -3
6 updated: 2019-09-30
7 prism_languages: [json, bash]
8 tags: [Featurable]
9 ---
10
11 ### npm equivalents
12
13 | npm | yarn |
14 | --- | ---- |
15 | `npm init` | `yarn init` |
16 | `npm install` | `yarn` |
17 | `npm install gulp --save` | `yarn add gulp` |
18 | `npm install gulp --save-dev --save-exact` | `yarn add gulp --dev --exact` |
19 | `npm install -g gulp` | `yarn global add gulp` |
20 | `npm update` | `yarn upgrade` |
21 | `./node_modules/.bin/gulp` | `yarn run gulp` |
22 {: .-left-align.-headers}
23
24 ### yarn install
25
26 ```
27 --no-lockfile
28 --pure-lockfile
29 --frozen-lockfile
30 --silent
31 --offline
32 --update-checksums
33 --check-files
34 --flat
35 --force
36 --ignore-scripts
37 --modules-folder <path>
38 --production[=true|false]
39 ```
40
41 These options are available for `yarn install`.
42
43 ### yarn add
44
45 ```
46 --dev
47 --peer
48 --optional
49 --exact
50 --tilde
51 ```
52
53 These options are available for `yarn add`.
54
55 ### Workspaces
56
57 In `package.json`:
58 {: .-setup}
59
60 ```json
61 "workspaces": [
62   "packages/*"
63 ]
64 ```
65
66 ```
67 jest/
68 ├─ package.json
69 └─ packages/
70    ├─ jest-matcher-utils/
71    │  └─ package.json
72    └─ jest-diff/
73       └─ package.json
74 ```
75 {: .-box-chars}
76
77 (New in 1.0) Allows monorepos to share packages with each other. See: [Introducing workspaces](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/)
78
79 ### Selective version resolution
80
81 In `package.json`:
82 {: .-setup}
83
84 ```json
85 "resolutions": {
86   "**/sass-brunch/node-sass": "4.5.2"
87 }
88 ```
89
90 (New in 1.0) Allows you to specify versions for sub-dependencies. See: [Selective version resolutions](https://github.com/yarnpkg/yarn/pull/4105)
91
92 ### Create
93
94 ```bash
95 yarn create react-app hello
96 ```
97
98 Install `create-react-app` and runs it. See: [yarn create](https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-yarn-create.md)