1

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();
Aiguo
  • 3,416
  • 7
  • 27
  • 52
  • Possible duplicate of [How can I disable AOT in angular2?](https://stackoverflow.com/questions/45814758/how-can-i-disable-aot-in-angular2) – 4castle May 06 '18 at 00:00
  • This is not a duplicate. See my updated post. – Aiguo May 06 '18 at 00:20
  • I don't understand how your edit makes it not a duplicate. Could you explain why the other question doesn't help? – 4castle May 06 '18 at 00:25
  • 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 May 06 '18 at 00:50
  • How is the production server different in that you wouldn't be able to use `-aot=false`? – 4castle May 06 '18 at 00:54

1 Answers1

0

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.

Vikas
  • 11,859
  • 7
  • 45
  • 69