1
votes

I am currently working on an application which is scheduled to go live soon. The problem is that I have to do a fair amount of cleanup for AOT, because when I run the following:

ng build --prod

it gives me error as my code is not fulfilling the requirements for AOT (example: not using service object directly in templates, etc.). So is there way to enable prod mode with AOT to get all the good stuff like treeshaking, minification, uglify, etc. that Angular prod mode offers and just leave AOT for the time being?

NOTE: I’m considering enabling the prod mode in main.ts file and not on my local machine, using the following method:

enableProdMode();
1
This is not a duplicate. See my updated post. - Aiguo
I don't understand how your edit makes it not a duplicate. Could you explain why the other question doesn't help? - 4castle
The post you mentioned is talking about building the app in prod mode on a local machine. But I’m talking about enabling prod mode on a production server. - Aiguo
How is the production server different in that you wouldn't be able to use -aot=false? - 4castle

1 Answers

0
votes

So is there way to enable prod mode with AOT to get all the good stuff like treeshaking, minification, uglify, etc. that Angular prod mode offers and just leave AOT for the time being?

You can migrate from Angular CLI to Webpack and tweak it accordingly for (local, development, production). Since Angular CLI v1.0 there’s the “eject” feature, that allows you to extract thewebpack config file and manipulate it as you wish.

Run ng eject so Angular CLI generates the webpack.config.js file.
Run npm install so the new dependencies generated by CLI are satisfied
Guide
Angular CLI to webpack
Production configuration for webpack
PS The Angular CLI hides the underlying complexity, once you eject, you have to deal with this complexity.