iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🎉

How to use .env.staging in Next.js

に公開
2022/03/09

About

I want to ensure that .env.staging is loaded correctly.

Current Situation

As of 2021-02-12, you can define three files—.env, .env.development, and .env.production—along with .env.*.local.

Since staging is not a default, I want to define .env.staging instead of just using .env.

Discussion

https://github.com/vercel/next.js/issues/12772

It seems the official team does not have a policy to support this yet.

What to do

Installing env-cmd and specifying the file seems to be the better solution.

"build:staging": "env-cmd -f .env.staging yarn build && yarn start"

In fact, this correctly loaded .env.staging and .env.production respectively!

https://stackoverflow.com/questions/59462614/how-to-use-diferent-env-files-with-nextjs

Discussion