生产环境变量好像没有设置

Sch*_*aki 4 typescript angular-cli angular angular12

编辑:我现在已将项目升级到 ng13,问题仍然存在。

我正在构建一个 Angular 12 13 应用程序(最初可能是在版本 8 或 9 中生成的)。我的构建命令是ng build --configuration=production --output-hashing=all

我希望MYAPP在应用程序启动时在浏览器控制台中看到写入内容,但没有出现。(实际上我想做其他事情,但 console.log 说明了我的问题)

以下片段来自main.ts

if (environment.production) {
  enableProdMode();
  console.log("MYAPP");
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

小智 5

你需要告诉 Angular 如何改变环境

在配置生产中的 Angular .json 中添加类似的内容

"fileReplacements": [
                            {
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prod.ts"
                            }
                        ],
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述