Skip to content
  • Sponsor facebook/create-react-app

  • Notifications You must be signed in to change notification settings
  • Fork 27k
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added instruction on how to install Prettier #2006

Merged
merged 7 commits into from
Jun 27, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added instruction on how to install Prettier
MrHus committed Jun 1, 2017
commit 4d46b0bbdfdf0da0f88086656cc7dc893f45f30a
46 changes: 46 additions & 0 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
- [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor)
- [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor)
- [Debugging in the Editor](#debugging-in-the-editor)
- [Formatting Code Automatically](#formatting-code-automatically)
- [Changing the Page `<title>`](#changing-the-page-title)
- [Installing a Dependency](#installing-a-dependency)
- [Importing a Component](#importing-a-component)
@@ -263,6 +264,51 @@ Then add the block below to your `launch.json` file and put it inside the `.vsco

Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor.

## Formatting Code Automatically
Prettier is an opinionated JavaScript formatter. With Prettier you can format the code you write automatically to ensure a code style within your project. See the [Prettier's github page](https://github.com/prettier/prettier) for more information, and look at this [page to see it in action](https://prettier.github.io/prettier/).

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

[Husky](https://github.com/typicode/husky) with npm:

```
npm install husky --save-dev
```

Husky makes it easy to use githooks as if they are npm scripts.

Next we need to install [lint-staged](https://github.com/okonet/lint-staged) with npm:

```
npm install lint-staged --save-dev
```
lint-staged allows us to run scripts on staged files in git. See this (blog post about lint-staged for more information)[https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8].

Now we can add prettier itself with npm:

```npm install prettier --save-dev```

Now we can make sure every file is formatted correctly by adding the following code to the `package.json`:

Add the following line to scripts:

```js
"precommit": "lint-staged"
```

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

```js
"lint-staged": {
"src/**/*.js": [
"prettier --single-quote --write",
"git add"
]
}
```

Next you might want to integrate Prettier in your favorite editor, read the section on [Editor Integration](https://github.com/prettier/prettier#editor-integration) on the Prettier github page.

## Changing the Page `<title>`

You can find the source HTML file in the `public` folder of the generated project. You may edit the `<title>` tag in it to change the title from “React App” to anything else.