.env.local.production
Review: ".env.local.production"
What it is
.env.local.production is a filename pattern used to store environment variables intended for a production build, typically used by developers and deployment pipelines. It’s a variant of the common dotenv convention (files named .env, .env.local, .env.production, etc.) that mixes two cues: “local” (machine-specific overrides) and “production” (production-specific settings). Its exact meaning and handling depend on the tooling and framework in use.
Use the wildcard *.local to catch all variants. .env.local.production
It is a local override for production-specific variables. In most development workflows, variables are loaded in a specific hierarchy. This file is typically used when you need to test a "production build" locally but want to use real production credentials (like a live Stripe key or production database URL) without committing them to your repository. Key Characteristics Local Only : By convention, any file ending in should be added to your .gitignore . It is meant to stay on your specific machine. High Priority : In frameworks like Next.js, .env.local Review: "
Document its purpose. Create a section in your README.md: Prefer standard names your framework recognizes (e
.local: Indicates that this file is local to your machine or the specific server instance. Crucially, local files should almost never be committed to Git.
Best practices
- Prefer standard names your framework recognizes (e.g., .env.production and .env.local) unless you control the tooling that reads .env.local.production.
- Never commit production secrets to git. Add the file to .gitignore and use secure secret managers for actual secret distribution (Vault, AWS Secrets Manager, GitHub Actions secrets, etc.).
- Document your environment-file precedence and loading behavior in repo README and deployment docs.
- Use CI/CD or deployment platform environment variable features instead of filesystem files when possible.
- Encrypt files at rest where needed (e.g., SOPS, git-crypt) and restrict access on build agents.
- Validate and lint environment variables during CI to catch missing or malformed required keys.
- If you do use a nonstandard name like .env.local.production, ensure your startup/build scripts explicitly load it (e.g., dotenv config in Node, or a small loader script).
At first glance, this file name looks like a typo or a conspiracy. However, for developers using frameworks like Next.js, Gatsby, or Vite, this specific naming convention solves a critical pain point: balancing runtime configuration with local overrides.
Use Case 2: Overriding Production Values for Local Build Artifacts
Sometimes, the process of building your application (minification, bundling, tree-shaking) requires specific flags. For example, you might enable source maps only in local production builds, but not in real production.