.gitignore for React Projects

Optimized .gitignore for React apps built with Create React App, Vite, or custom webpack. Covers build folders, caches, and environment variable files.

Framework

Detailed Explanation

React projects inherit most patterns from Node.js but have additional framework-specific directories and build artifacts to exclude. The right .gitignore depends on your build tool.

Create React App (CRA):

  • build/ — The production build output from npm run build. This directory contains minified, hashed JavaScript and CSS bundles. It is fully reproducible and should be built by CI, not committed.
  • node_modules/ — As with all Node.js projects, never commit dependencies.

Vite-based React projects:

  • dist/ — Vite outputs the production build to dist/ by default instead of build/.
  • .vite/ — Vite's dependency pre-bundling cache directory.

Common React patterns:

  • .env.local, .env.development.local, .env.production.local — Environment overrides containing API keys or feature flags. CRA and Vite both load these automatically. The base .env file is typically committed with non-sensitive defaults, but .env.local must always be ignored.
  • coverage/ — Test coverage from Jest or Vitest.
  • storybook-static/ — Built Storybook documentation site. If you use Storybook for component development, ignore the static output.
  • .eslintcache — ESLint caching file that speeds up linting but is machine-specific.
  • *.tsbuildinfo — TypeScript incremental compilation cache. Useful locally but not needed in the repo.

Monorepo considerations: If your React app lives inside a monorepo (Turborepo, Nx, Lerna), each package may have its own dist/ or build/ directory. Use patterns like **/dist/ or add a root-level .gitignore that covers all workspaces.

What to commit: Always commit package-lock.json, tsconfig.json, and .eslintrc configuration files. These ensure consistent development environments across your entire team.

Use Case

A frontend team migrating from Create React App to Vite needs to update their .gitignore to cover the new dist/ output directory while preserving existing ignore rules.

Try It — .gitignore Generator

Open full tool