You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
Copy file name to clipboardexpand all lines: packages/react-scripts/template/README.md
+125-62
Original file line number
Diff line number
Diff line change
@@ -275,14 +275,14 @@ Prettier is an opinionated JavaScript formatter. With Prettier you can format th
275
275
276
276
To format our code whenever we make a commit in git, we need to install the following dependencies:
277
277
278
-
```
279
-
npm install --save-dev husky lint-staged prettier
278
+
```sh
279
+
npm install --save husky lint-staged prettier
280
280
```
281
281
282
-
or if you use Yarn:
282
+
Alternatively you may use `yarn`:
283
283
284
-
```
285
-
yarn add --dev husky lint-staged prettier
284
+
```sh
285
+
yarn add husky lint-staged prettier
286
286
```
287
287
288
288
*`husky` makes it easy to use githooks as if they are npm scripts.
@@ -293,29 +293,26 @@ Now we can make sure every file is formatted correctly by adding a few lines to
293
293
294
294
Add the following line to `scripts` section:
295
295
296
-
```js
297
-
{
298
-
// ...
296
+
```diff
299
297
"scripts": {
300
-
// ...
301
-
"precommit":"lint-staged"
302
-
},
303
-
// ...
304
-
}
298
+
+ "precommit": "lint-staged",
299
+
"start": "react-scripts start",
300
+
"build": "react-scripts build",
305
301
```
306
302
307
303
Next we add a 'lint-staged' field to the `package.json`, for example:
308
304
309
-
```js
310
-
{
311
-
// ...
312
-
"lint-staged": {
313
-
"src/**/*.{js,jsx}": [
314
-
"prettier --single-quote --write",
315
-
"git add"
316
-
]
317
-
}
318
-
}
305
+
```diff
306
+
"dependencies": {
307
+
// ...
308
+
},
309
+
+ "lint-staged": {
310
+
+ "src/**/*.{js,jsx}": [
311
+
+ "prettier --single-quote --write",
312
+
+ "git add"
313
+
+ ]
314
+
+ },
315
+
"scripts": {
319
316
```
320
317
321
318
Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx}"` to format your entire project for the first time.
@@ -336,15 +333,17 @@ If you use a custom server for your app in production and want to modify the tit
336
333
337
334
The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`:
338
335
339
-
```
340
-
npm install --save <library-name>
336
+
```sh
337
+
npm install --save react-router
341
338
```
342
339
343
-
Alternatively you may also use `yarn`:
340
+
Alternatively you may use `yarn`:
344
341
342
+
```sh
343
+
yarn add react-router
345
344
```
346
-
yarn add <library-name>
347
-
```
345
+
346
+
This works for any library, not just `react-router`.
348
347
349
348
## Importing a Component
350
349
@@ -519,9 +518,16 @@ Following this rule often makes CSS preprocessors less useful, as features like
519
518
520
519
First, let’s install the command-line interface for Sass:
521
520
521
+
```sh
522
+
npm install --save node-sass-chokidar
522
523
```
523
-
npm install node-sass-chokidar --save-dev
524
+
525
+
Alternatively you may use `yarn`:
526
+
527
+
```sh
528
+
yarn add node-sass-chokidar
524
529
```
530
+
525
531
Then in `package.json`, add the following lines to `scripts`:
526
532
527
533
```diff
@@ -557,8 +563,14 @@ At this point you might want to remove all CSS files from the source control, an
557
563
558
564
As a final step, you may find it convenient to run `watch-css` automatically with `npm start`, and run `build-css` as a part of `npm run build`. You can use the `&&` operator to execute two scripts sequentially. However, there is no cross-platform way to run two scripts in parallel, so we will install a package for this:
559
565
566
+
```sh
567
+
npm install --save npm-run-all
560
568
```
561
-
npm install --save-dev npm-run-all
569
+
570
+
Alternatively you may use `yarn`:
571
+
572
+
```sh
573
+
yarn add npm-run-all
562
574
```
563
575
564
576
Then we can change `start` and `build` scripts to include the CSS preprocessor commands:
@@ -716,9 +728,14 @@ You don’t have to use [React Bootstrap](https://react-bootstrap.github.io) tog
716
728
717
729
Install React Bootstrap and Bootstrap from npm. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well:
718
730
731
+
```sh
732
+
npm install --save react-bootstrap bootstrap@3
719
733
```
720
-
npm install react-bootstrap --save
721
-
npm install bootstrap@3 --save
734
+
735
+
Alternatively you may use `yarn`:
736
+
737
+
```sh
738
+
yarn add react-bootstrap bootstrap@3
722
739
```
723
740
724
741
Import Bootstrap CSS and optionally Bootstrap theme CSS in the beginning of your ```src/index.js``` file:
@@ -757,7 +774,7 @@ Recent versions of [Flow](http://flowtype.org/) work with Create React App proje
757
774
758
775
To add Flow to a Create React App project, follow these steps:
1. Run `npm install --save flow-bin` (or `yarn add flow-bin`).
761
778
2. Add `"flow": "flow"` to the `scripts` section of your `package.json`.
762
779
3. Run `npm run flow init` (or `yarn flow init`) to create a [`.flowconfig` file](https://flowtype.org/docs/advanced-configuration.html) in the root directory.
763
780
4. Add `// @flow` to any files you want to type check (for example, to `src/App.js`).
@@ -1226,12 +1243,20 @@ This test mounts a component and makes sure that it didn’t throw during render
1226
1243
1227
1244
When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior.
1228
1245
1229
-
If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). You can write a smoke test with it too:
1246
+
If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). To install it, run:
1247
+
1248
+
```sh
1249
+
npm install --save enzyme react-test-renderer
1250
+
```
1251
+
1252
+
Alternatively you may use `yarn`:
1230
1253
1231
1254
```sh
1232
-
npm install --save-dev enzyme react-test-renderer
1255
+
yarn add enzyme react-test-renderer
1233
1256
```
1234
1257
1258
+
You can write a smoke test with it too:
1259
+
1235
1260
```js
1236
1261
importReactfrom'react';
1237
1262
import { shallow } from'enzyme';
@@ -1270,18 +1295,24 @@ Additionally, you might find [jest-enzyme](https://github.com/blainekasten/enzym
1270
1295
expect(wrapper).toContainReact(welcome)
1271
1296
```
1272
1297
1273
-
To setup jest-enzyme with Create React App, follow the instructions for [initializing your test environment](#initializing-test-environment) to import `jest-enzyme`.
1298
+
To enable this, install `jest-enzyme`:
1299
+
1300
+
```sh
1301
+
npm install --save jest-enzyme
1302
+
```
1303
+
1304
+
Alternatively you may use `yarn`:
1274
1305
1275
1306
```sh
1276
-
npm install --save-dev jest-enzyme
1307
+
yarn add jest-enzyme
1277
1308
```
1278
1309
1310
+
Import it in [`src/setupTests.js`](#initializing-test-environment) to make its matchers available in every test:
1311
+
1279
1312
```js
1280
-
// src/setupTests.js
1281
1313
import'jest-enzyme';
1282
1314
```
1283
1315
1284
-
1285
1316
### Using Third Party Assertion Libraries
1286
1317
1287
1318
We recommend that you use `expect()` for assertions and `jest.fn()` for spies. If you are having issues with them please [file those against Jest](https://github.com/facebook/jest/issues/new), and we’ll fix them. We intend to keep making them better for React, supporting, for example, [pretty-printing React elements as JSX](https://github.com/facebook/jest/pull/1566).
@@ -1392,14 +1423,22 @@ The build command will check for linter warnings and fail if any are found.
1392
1423
By default, the `package.json` of the generated project looks like this:
1393
1424
1394
1425
```js
1395
-
// ...
1396
1426
"scripts": {
1397
-
// ...
1427
+
"start":"react-scripts start",
1428
+
"build":"react-scripts build",
1398
1429
"test":"react-scripts test --env=jsdom"
1399
-
}
1400
1430
```
1401
1431
1402
-
If you know that none of your tests depend on [jsdom](https://github.com/tmpvar/jsdom), you can safely remove `--env=jsdom`, and your tests will run faster.<br>
1432
+
If you know that none of your tests depend on [jsdom](https://github.com/tmpvar/jsdom), you can safely remove `--env=jsdom`, and your tests will run faster:
1433
+
1434
+
```diff
1435
+
"scripts": {
1436
+
"start":"react-scripts start",
1437
+
"build":"react-scripts build",
1438
+
-"test":"react-scripts test --env=jsdom"
1439
+
+"test":"react-scripts test"
1440
+
```
1441
+
1403
1442
To help you make up your mind, here is a list of APIs that **need jsdom**:
1404
1443
1405
1444
* Any browser globals like `window` and `document`
@@ -1473,18 +1512,22 @@ Styleguidist combines of a style guide, where all your components are presented
1473
1512
First, install Styleguidist:
1474
1513
1475
1514
```sh
1476
-
npm install --save-dev react-styleguidist
1515
+
npm install --save react-styleguidist
1477
1516
```
1478
1517
1479
-
Then, add these scripts to your `package.json`:
1518
+
Alternatively you may use `yarn`:
1480
1519
1481
1520
```sh
1482
-
{
1483
-
"scripts": {
1484
-
"styleguide": "styleguidist server",
1485
-
"styleguide:build": "styleguidist build"
1486
-
}
1487
-
}
1521
+
yarn add react-styleguidist
1522
+
```
1523
+
1524
+
Then, add these scripts to your `package.json`:
1525
+
1526
+
```diff
1527
+
"scripts": {
1528
+
+"styleguide":"styleguidist server",
1529
+
+"styleguide:build":"styleguidist build",
1530
+
"start":"react-scripts start",
1488
1531
```
1489
1532
1490
1533
Then, run the following command inside your app’s directory:
@@ -1608,21 +1651,36 @@ bloat is coming from.
1608
1651
1609
1652
To add Source map explorer to a Create React App project, follow these steps:
1610
1653
1654
+
```sh
1655
+
npm install --save source-map-explorer
1611
1656
```
1612
-
npm install source-map-explorer --save-dev
1657
+
1658
+
Alternatively you may use `yarn`:
1659
+
1660
+
```sh
1661
+
yarn add source-map-explorer
1613
1662
```
1614
1663
1615
-
Then in `package.json`, add the following line to `scripts`
1616
-
On Windows you will have to type the full file path out.
1664
+
Then in `package.json`, add the following line to `scripts`:
>This doesn't quite work on Windows because it doesn't automatically expand `*` in the filepath. For now, the workaround is to look at the full hashed filename in `build/static/js` (e.g. `main.89b7e95a.js`) and copy it into `package.json` when you're running the analyzer. For example:
>Unfortunately it will be different after every build. You can express support for fixing this on Windows [in this issue](https://github.com/danvk/source-map-explorer/issues/52).
1683
+
1626
1684
Then to analyze the bundle run the production build then run the analyze
1627
1685
script.
1628
1686
@@ -1827,18 +1885,23 @@ Now, whenever you run `npm run build`, you will see a cheat sheet with instructi
1827
1885
To publish it at [https://myusername.github.io/my-app](https://myusername.github.io/my-app), run:
1828
1886
1829
1887
```sh
1830
-
npm install --save-dev gh-pages
1888
+
npm install --save gh-pages
1889
+
```
1890
+
1891
+
Alternatively you may use `yarn`:
1892
+
1893
+
```sh
1894
+
yarn add gh-pages
1831
1895
```
1832
1896
1833
1897
Add the following scripts in your `package.json`:
1834
1898
1835
-
```js
1836
-
// ...
1899
+
```diff
1837
1900
"scripts": {
1838
-
// ...
1839
-
"predeploy": "npm run build",
1840
-
"deploy": "gh-pages -d build"
1841
-
}
1901
+
+"predeploy": "npm run build",
1902
+
+"deploy": "gh-pages -d build",
1903
+
"start": "react-scripts start",
1904
+
"build": "react-scripts build",
1842
1905
```
1843
1906
1844
1907
The `predeploy` script will run automatically before `deploy` is run.
0 commit comments