Next.js Discord

Discord Forum

Custom environments beyond prod, dev, preview?

Unanswered
Leonberger posted this in #help-forum
Open in Discord
LeonbergerOP
Hi, is it possible to define custom environments with their own set of env variables beyond just prod, dev, and preview?

We're trying to serve different prod deployments of the same branch reading different environment variables.

The only options we have found are either hardcoding it in code (not ideal), or using the preview environment and customizing it for each branch, though we're also not sure if it's a good idea to use the preview deployments as a production site.

1 Reply

Holland Lop
Based on CI/CD option, you can create different .env.* and then rename it before build:
files:
.env.apple
.env.banana
.env.orange

package.json:
"dev:apple": "mv .env.apple .env"
"build:apple ": "mv .env.apple .env"

and then run commands:
npm run dev:apple
npm run build:apple