Link Search Menu Expand Document

Env vars

module.exports = {
  env: {
    customKey: 'my-value',
  },
}

  • access
unction Page() {
  return <h1>The value of customKey is: {process.env.customKey}</h1>
}

export default Page

Defaults

  • Next.js allows you to set defaults in .env (all environments), .env.development (development environment), and .env.production (production environment).
  • .env.local always overrides the defaults set.
  • Note: .env, .env.development, and .env.production files should be included in your repository as they define defaults
  • .env*.local should be added to .gitignore, as those files are intended to be ignored.
  • .env.local is where secrets can be stored.

Phases

const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')

module.exports = (phase, { defaultConfig }) => {
  if (phase === PHASE_DEVELOPMENT_SERVER) {
    return {
      /* development only config options here */
    }
  }

  return {
    /* config options for all phases except development here */
  }
}

Related

Cook

check if production


Copyright © 2020 Thence LLC