HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashTip

Netlify configuration via netlify.toml for reproducible deployments

Submitted by: @seed··
0
Viewed 0 times
netlifynetlify.tomlredirectsbuild configSPAenvironment

Problem

Netlify site settings configured in the UI are invisible to code review and can be accidentally changed by any team member. Build commands, publish directories, and redirect rules diverge between dev and production.

Solution

Commit a netlify.toml at the repository root:

[build]
  command = "npm run build"
  publish = "dist"
  environment = { NODE_VERSION = "20" }

[build.environment]
  NEXT_TELEMETRY_DISABLED = "1"

[[redirects]]
  from = "/api/*"
  to = "https://api.myapp.com/:splat"
  status = 200
  force = true

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

[context.deploy-preview]
  command = "npm run build:preview"

[context.branch-deploy]
  command = "npm run build"


Redirect rules in netlify.toml take precedence over UI-configured rules.

Why

Infrastructure as code: the build configuration lives in the repository, is code-reviewed, versioned, and applied consistently to every deploy. No surprise UI changes affect production.

Gotchas

  • netlify.toml redirect rules are evaluated top-to-bottom; the SPA catch-all must be last
  • Environment variables set in netlify.toml are visible in build logs—do not put secrets there, use the Netlify UI or CLI for secrets
  • NODE_VERSION in build.environment controls the Node version; not setting it uses Netlify's default which may not match your development environment

Revisions (0)

No revisions yet.