Skip to content

Instantly share code, notes, and snippets.

Last active January 12, 2022 00:41
What would you like to do?
Adding Prettier to a project

Adding Prettier to a Project

Basic steps for adding Prettier to a project and setting up a pre-commit hook when not using any other linter. Most of these steps can be found in the docs and through other links in the docs.

  1. Install prettier:
$ npm install --save-dev --save-exact prettier
  1. Create an empty config file to let tools know you're using Prettier:
$ echo {}> .prettierrc.json
  1. Create a .prettierignore file to let tools know which files NOT to format. node_modules are ignored by default. Some suggestions:
  1. Manually run Prettier to re-format all the files in the project:
$ npx prettier --write .
  1. Set up your code editor to auto-format on save for ease of use. See instructions for various editors.
  2. Set up commit hooks with pretty-quick and husky. First, install them as dev dependencies:
$ npm i --save-dev pretty-quick husky
  1. Finally, add the pre-commit instructions to your package.json file:
"husky": {
  "hooks": {
    "pre-commit": "pretty-quick --staged"

Now when you commit your changes, files in the commit will automatically be formatted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment