我想使用单个 .env 文件来动态处理所有环境。有可能做到吗? 我尝试将不同环境的所有变量写入单个 .env 中,但这似乎不是正确的过程。 基本上,我需要使用单个 .env 文件运行我的角度应用程序,而不是编写不同的环境。
转到你的
angular.json
检查fileReplacements
下名为configurations
的属性,Angular总是只查看environment.json
,我们用它来根据环境复制/粘贴内容,通过这个配置,如果你删除fileReplacements
,只有一个文件,将用于所有环境。
"configurations": {
"development": { … },
"production": { … },
"staging": {
"fileReplacements": [
{ // remove this!
"replace": "src/environments/environment.ts", // remove this!
"with": "src/environments/environment.staging.ts" // remove this!
} // remove this!
]
}
}