Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit 9e64ca3

Browse files
gaearonwmonk
authored andcommitted
Minor code style edits to user guide (#2660)
* Minor code style edits to user guide * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md
1 parent a7efc39 commit 9e64ca3

File tree

1 file changed

+125
-62
lines changed

1 file changed

+125
-62
lines changed

packages/react-scripts/template/README.md

+125-62
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,14 @@ Prettier is an opinionated JavaScript formatter. With Prettier you can format th
275275

276276
To format our code whenever we make a commit in git, we need to install the following dependencies:
277277

278-
```
279-
npm install --save-dev husky lint-staged prettier
278+
```sh
279+
npm install --save husky lint-staged prettier
280280
```
281281

282-
or if you use Yarn:
282+
Alternatively you may use `yarn`:
283283

284-
```
285-
yarn add --dev husky lint-staged prettier
284+
```sh
285+
yarn add husky lint-staged prettier
286286
```
287287

288288
* `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
293293

294294
Add the following line to `scripts` section:
295295

296-
```js
297-
{
298-
// ...
296+
```diff
299297
"scripts": {
300-
// ...
301-
"precommit": "lint-staged"
302-
},
303-
// ...
304-
}
298+
+ "precommit": "lint-staged",
299+
"start": "react-scripts start",
300+
"build": "react-scripts build",
305301
```
306302

307303
Next we add a 'lint-staged' field to the `package.json`, for example:
308304

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": {
319316
```
320317

321318
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
336333

337334
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`:
338335

339-
```
340-
npm install --save <library-name>
336+
```sh
337+
npm install --save react-router
341338
```
342339

343-
Alternatively you may also use `yarn`:
340+
Alternatively you may use `yarn`:
344341

342+
```sh
343+
yarn add react-router
345344
```
346-
yarn add <library-name>
347-
```
345+
346+
This works for any library, not just `react-router`.
348347

349348
## Importing a Component
350349

@@ -519,9 +518,16 @@ Following this rule often makes CSS preprocessors less useful, as features like
519518

520519
First, let’s install the command-line interface for Sass:
521520

521+
```sh
522+
npm install --save node-sass-chokidar
522523
```
523-
npm install node-sass-chokidar --save-dev
524+
525+
Alternatively you may use `yarn`:
526+
527+
```sh
528+
yarn add node-sass-chokidar
524529
```
530+
525531
Then in `package.json`, add the following lines to `scripts`:
526532

527533
```diff
@@ -557,8 +563,14 @@ At this point you might want to remove all CSS files from the source control, an
557563

558564
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:
559565

566+
```sh
567+
npm install --save npm-run-all
560568
```
561-
npm install --save-dev npm-run-all
569+
570+
Alternatively you may use `yarn`:
571+
572+
```sh
573+
yarn add npm-run-all
562574
```
563575

564576
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
716728

717729
Install React Bootstrap and Bootstrap from npm. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well:
718730

731+
```sh
732+
npm install --save react-bootstrap bootstrap@3
719733
```
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
722739
```
723740

724741
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
757774

758775
To add Flow to a Create React App project, follow these steps:
759776

760-
1. Run `npm install --save-dev flow-bin` (or `yarn add --dev flow-bin`).
777+
1. Run `npm install --save flow-bin` (or `yarn add flow-bin`).
761778
2. Add `"flow": "flow"` to the `scripts` section of your `package.json`.
762779
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.
763780
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
12261243

12271244
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.
12281245

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`:
12301253

12311254
```sh
1232-
npm install --save-dev enzyme react-test-renderer
1255+
yarn add enzyme react-test-renderer
12331256
```
12341257

1258+
You can write a smoke test with it too:
1259+
12351260
```js
12361261
import React from 'react';
12371262
import { shallow } from 'enzyme';
@@ -1270,18 +1295,24 @@ Additionally, you might find [jest-enzyme](https://github.com/blainekasten/enzym
12701295
expect(wrapper).toContainReact(welcome)
12711296
```
12721297

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`:
12741305

12751306
```sh
1276-
npm install --save-dev jest-enzyme
1307+
yarn add jest-enzyme
12771308
```
12781309

1310+
Import it in [`src/setupTests.js`](#initializing-test-environment) to make its matchers available in every test:
1311+
12791312
```js
1280-
// src/setupTests.js
12811313
import 'jest-enzyme';
12821314
```
12831315

1284-
12851316
### Using Third Party Assertion Libraries
12861317

12871318
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.
13921423
By default, the `package.json` of the generated project looks like this:
13931424

13941425
```js
1395-
// ...
13961426
"scripts": {
1397-
// ...
1427+
"start": "react-scripts start",
1428+
"build": "react-scripts build",
13981429
"test": "react-scripts test --env=jsdom"
1399-
}
14001430
```
14011431
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+
14031442
To help you make up your mind, here is a list of APIs that **need jsdom**:
14041443
14051444
* Any browser globals like `window` and `document`
@@ -1473,18 +1512,22 @@ Styleguidist combines of a style guide, where all your components are presented
14731512
First, install Styleguidist:
14741513
14751514
```sh
1476-
npm install --save-dev react-styleguidist
1515+
npm install --save react-styleguidist
14771516
```
14781517
1479-
Then, add these scripts to your `package.json`:
1518+
Alternatively you may use `yarn`:
14801519
14811520
```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",
14881531
```
14891532
14901533
Then, run the following command inside your app’s directory:
@@ -1608,21 +1651,36 @@ bloat is coming from.
16081651
16091652
To add Source map explorer to a Create React App project, follow these steps:
16101653
1654+
```sh
1655+
npm install --save source-map-explorer
16111656
```
1612-
npm install source-map-explorer --save-dev
1657+
1658+
Alternatively you may use `yarn`:
1659+
1660+
```sh
1661+
yarn add source-map-explorer
16131662
```
16141663
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`:
16171665
16181666
```diff
16191667
"scripts": {
1668+
+ "analyze": "source-map-explorer build/static/js/main.*",
16201669
"start": "react-scripts start",
16211670
"build": "react-scripts build",
16221671
"test": "react-scripts test --env=jsdom",
1623-
+ "analyze": "source-map-explorer build/static/js/main.* "
16241672
```
16251673
1674+
>**Note:**
1675+
>
1676+
>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:
1677+
>
1678+
>```diff
1679+
>+ "analyze": "source-map-explorer build/static/js/main.89b7e95a.js",
1680+
>```
1681+
>
1682+
>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+
16261684
Then to analyze the bundle run the production build then run the analyze
16271685
script.
16281686
@@ -1827,18 +1885,23 @@ Now, whenever you run `npm run build`, you will see a cheat sheet with instructi
18271885
To publish it at [https://myusername.github.io/my-app](https://myusername.github.io/my-app), run:
18281886

18291887
```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
18311895
```
18321896

18331897
Add the following scripts in your `package.json`:
18341898

1835-
```js
1836-
// ...
1899+
```diff
18371900
"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",
18421905
```
18431906

18441907
The `predeploy` script will run automatically before `deploy` is run.

0 commit comments

Comments
 (0)