我将三个环境变量分别存储在.env.development、.env.staging和.env.production中。当我运行next build时,我希望能够选择在构建过程中使用的环境。这有可能吗?
我看过这篇文章:https://nextjs.org/docs/basic-features/environment-variables
看起来它只能有两组环境变量,而不是三个。我只想看看有没有可能有三个。
发布于 2022-08-14 21:32:23
是的,你可以使用任意多的环境。我个人使用env-cmd包,但也有其他选择,如dotenv包。
在package.json文件中设置构建脚本,如下所示:
"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"
}https://stackoverflow.com/questions/73329300
复制相似问题