Search code examples
angularoptimizationenvironmentproduction-environment

Is production mode is not related to optimization of the files in angular directly?


I have a query related to production mode in angular. So in a new angular project, we have two files inside the environment folder one is the environment.ts with production set to false and the other one is the environment.prod.ts with production set to true.

So here if I am also setting production to true in the environment.ts file and then running the "ng build" command so this means I am building an app in production mode? because now it will call enableProdMode() method.

The only difference between the build created by "ng build" and "ng build --prod" commands are the optimization of the files. The build created by "ng build --prod" is smaller in size compared to the build created by "ng build".

So my query is here: "Files optimization like minification, uglification, extracting CSS, tree shaking, AOT compilation, and no generation of source-map files are not related to "Prod Mode" but they are like extra features which we enable by defining them in angular.json configuration?"

Conclusion: we can build an angular app in prod mode just by setting production to true even in the environment.ts file but this prod build will not be optimized one?

Thanks


Solution

  • For sure, you can create N environments with custom properties.

    So you can have a production environment, in a debug build. As you say the parameter prod is used to switch configuration inside the angular.json.

    You can even use aot, source map, and so on in the debug build.

    So for replying to your question: yes you can generate a debug with the production environment and vice-versa.