Please, watch this great introduction video from the creator of Prettier (8 minutes long):
Node.js v10.13.0 or newer.
There are two options:
If you are creating a new project, easiest way to get started is to use this template. Go to https://github.com/nemanjakrstic/prettier-template and click on the "Use this template" button.
First, install the Prettier:
$ npm install prettier --save-dev
Next, add these scripts to your package.json
file:
package.json
{
"scripts": {
"format": "prettier --write .",
"format:check": "prettier --check ."
}
}
Copy the Prettier config file in the root of your project:
You can download the file directly or use the command line:
$ curl https://raw.githubusercontent.com/nemanjakrstic/prettier-template/master/.prettierrc -o .prettierrc
Since we want to format all supported files in the project, except the package-lock.json file, we need to create a Prettier ignore file in the root of the project:
You can download the file directly or use the command line:
$ curl https://raw.githubusercontent.com/nemanjakrstic/prettier-template/master/.prettierignore -o .prettierignore
To format all the files manually:
$ npm run format
Check if all files are formatted properly:
$ npm run format:check
It's strongly recommended to setup your editor to run the Prettier on every file save to take all the advantages that Prettier offers.
Check out the official docs on how to setup your editor integration: https://prettier.io/docs/en/editors.html
For more information, check out the official website: https://prettier.io