Reputation: 1892
I have three environment variables stored in .env.development
, .env.staging
and .env.production
separately. And when I run next build
, I wish I can choose the environment that I am going to use during the build process. Is that possible?
I have viewed this article: https://nextjs.org/docs/basic-features/environment-variables
And it looks like it can only have two sets of environment variables rather than three. I just want to check if there's a possibility to have three.
Upvotes: 1
Views: 1595
Reputation: 341
Yes you can use as many environments as you please. I personally use the env-cmd
package, but there are alternatives available as well such as the dotenv
package.
Setup the build scripts in your package.json
file like so:
"scripts": {
"build:development": "env-cmd -f .env.development next build",
"build:staging": "env-cmd -f .env.staging next build",
"build:production": "env-cmd -f .env.production next build"
}
Upvotes: 2