Ignoring Files with .prettierignore
You'll learn how to prevent Prettier from formatting certain files and folders that shouldn't be touched.
Why Ignore Files?
Not every file in your project should be formatted by Prettier. Build outputs, third-party dependencies, generated code, and certain data files should stay exactly as they are. Reformatting these files wastes time, creates unnecessary changes in version control, and can even break functionality.
The .prettierignore file works like a "do not format" list for Prettier. It uses the same pattern syntax as .gitignore, making it familiar and easy to use.
How It Works
Create a .prettierignore file in your project root and list the files or directories you want Prettier to skip. Each line represents a pattern:
# Build outputs
dist/
build/
*.min.js
# Dependencies
node_modules/
vendor/
# Generated files
coverage/
.next/
.cache/
# Specific files
package-lock.json
pnpm-lock.yaml
When you run Prettier, it reads this file first and automatically skips anything matching these patterns. This keeps your formatting runs fast and focused only on your source code.
Common Patterns
Most projects ignore node_modules/ (dependencies), build folders like dist/ or build/, and lock files that have specific machine-generated formatting. You might also ignore .md files if you want manual control over documentation formatting.
Think of .prettierignore as a bouncer at a club: it decides who gets in (formatted) and who stays out (untouched).
Key Takeaway: Use .prettierignore to exclude build outputs, dependencies, and generated files from Prettier formatting, keeping your formatting runs efficient and conflict-free.