How to add Prettier to your project

Bjorn Krolsavatar

Bjorn Krols

Published on
13 August 2021
npm install --save-dev prettier

format.sh

#!/bin/bash

set -e

npx prettier --write . --ignore-path .gitignore

package.json

{
  "scripts": {
    "format": "bash scripts/format.sh"
  }
}
npm install --save-dev husky pretty-quick

prepare.sh

#!/bin/bash

set -e

npx husky install

package.json

{
  "scripts": {
    "format": "bash scripts/format.sh",
    "prepare": "bash scripts/prepare.sh"
  }
}
npm run prepare
npx husky add .husky/pre-commit

.husky/pre-commit

npx pretty-quick --staged

.husky/pre-commit should be executable.

chmod +x pre-commit

Subscribe to our newsletter

The latest news, articles, and resources, sent to your inbox weekly.

More like this