Is enableProdMode(); and build –prod are equivalen

2019-09-14 00:27发布

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?

2条回答
Luminary・发光体
2楼-- · 2019-09-14 01:15

But remember that if you do something like this:

ng build --env=dev --prod

then flags from production envy are going to be overwritten. I checked it as I was still having problems with performance despite using --prod flag on non prod envy. This is important when building demos, benchmarking builds and so on.

查看更多
贼婆χ
3楼-- · 2019-09-14 01:17

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.

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();
}

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

查看更多
登录 后发表回答