Adds prettier to your project in one command. Just run npx prettierify in the root of your project.
Optionally create a file ~/.prettierrc in your home directory.
At recogizer, for example, we use the following config:
{
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
The command npx prettierify does several things:
- Runs
npm i -D husky lint-staged prettier - Creates a file .prettierrc. It is a copy of
~/.prettierrcfrom your home directory. - Adds lint-staged block to
package.json.
"lint-staged": {
"*.{js,json,css}": ["prettier --write", "git add"],
"*.ts": [
"tslint --fix -c ./tslint.json 'src/**/*{.ts,.tsx}'",
"prettier --write",
"git add"
]
},
- In
package.json, adds a line to scripts:"precommit": "lint-staged" - Finally,
prettierifyappliesprettierto all files in your project.
Steps 1-4 add a pre-commit hook that guarantees all your files will be formatted before commits.