Docs
Prettier Installation

Prettier Installation

How to install Prettier in your project.

Why Use Prettier?

  • Maintains consistent code style
  • Catches potential errors and bad practices
  • Improves code readability
  • Enforces team-wide coding standards
  • Can automatically fix many issues

Installing Prettier

Follow these steps to install and set up Prettier in your project:

Installation Steps

Open your terminal and navigate to your project directory.

Install Prettier as a Dev Dependency:

npm install --save-dev prettier

Create a Configuration File:

To customize Prettier's behavior, create a .prettierrc file in the root of your project. Here's an example configuration:

{
  "printWidth": 80,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSpacing": true
}

Add a .prettierignore File:

Create a .prettierignore file to specify files or directories that Prettier should ignore. Example:

node_modules
dist
build

Add a script to your package.json file:

{
  "scripts": {
    "format": "prettier --write ."
  }
}