是“enableProdMode()"和“构建 --prod"相等的? [英] Are "enableProdMode()" and "build --prod" equivalent?

查看:96
本文介绍了是“enableProdMode()"和“构建 --prod"相等的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个愚蠢的问题.我想知道如何加速我的应用程序.在大多数情况下,流行的一种是在构建期间使用 --prod 标志.但我也找到了一个建议来启用 Angular 生产模式enableProdMode();main.ts 中.这些动作是否相同并触发相同的机制?

I have one silly question. I'm wondering about ways to speed up my app. In most cases the popular one is to use --prod flag during build. But also I found an advice to enable Angular production mode with enableProdMode(); in main.ts. Are these actions the same and trigger the same mechanism?

推荐答案

--prod 标志触发 --environment=prod 标志(除其他外).这意味着编译时会使用.angular-cli.jsonenvironments 数组中定义为prod 的环境文件.

The --prod flag triggers the --environment=prod flag (among other things). This means that the environment file defined as prod in the environments array of the .angular-cli.json is used during compilation.

如果你有默认的 main.ts 这确实意味着它运行 enabledProdMode().因为他们用它来触发它:

If you have the default main.ts this will indeed mean it runs enabledProdMode(). Because they use this to trigger it:

if (environment.production) {
    enableProdMode();
}

在环境文件中,production 属性设置为 true.

and in the environment file the production property is set to true.

这篇关于是“enableProdMode()"和“构建 --prod"相等的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆