Ignoring Files with .prettierignore
What you'll learn: How to prevent Prettier from formatting files that shouldn't be touched, like build output and third-party code.
Why You Need .prettierignore
Not every file in your project should be formatted. Build artifacts (compiled code in dist/ or build/), dependencies in node_modules/, auto-generated files, and vendor libraries should stay exactly as they are. Formatting these wastes time and can even break functionality. The .prettierignore file lets you exclude specific files and directories from Prettier's reach.
How .prettierignore Works
Create a .prettierignore file in your project root. It uses the same pattern syntax as .gitignore—each line specifies a path pattern to ignore:
# Dependencies
node_modules/
# Build output
dist/
build/
*.min.js
# Generated files
coverage/
.cache/
*.generated.js
# Vendor libraries
public/vendor/
Think of .prettierignore as a "do not disturb" sign for Prettier—marking which rooms (directories) and items (files) it should skip entirely.
Common Patterns to Ignore
- Dependencies:
node_modules/is the most obvious—you never format installed packages - Build artifacts:
dist/,build/,out/contain compiled code that will be regenerated anyway - Minified files:
*.min.jsare intentionally compressed - Generated code: Database migrations, API client libraries, or any file created by tools
- Large data files: JSON fixtures or configuration that would slow Prettier down
When you run prettier --write ., Prettier automatically respects .prettierignore, skipping everything listed inside.
Key Takeaway: Use .prettierignore to exclude build output, dependencies, and generated files from formatting—keeping Prettier fast and focused on the source code you actually write.