Reputation: 6206
I'm wondering how I can implement / activate AOT (Ahead Of Time compilation) in a Angular CLI project that is generated without AOT.
Nowadays you can just generate a new app and use the --aot flag, but a while back this flag wasn't available. And guess what, my app is a few months old!
So I'm experimenting with AOT but couldn't find a clear way to implement it. First I thought I just needed:
ng build --prod --aot
But this was wrong.
Possible solution is to generate a new app with the flag and compare the files to see where the differences are. Did someone already accomplish this?
Upvotes: 1
Views: 489
Reputation: 36594
There is nothing AoT
specific to ng mew
.
You should be able to just run ng build --aot
(often used with -prod
, although not a necessity) or ng serve --aot
even.
Note that AoT has historically been half baked, in general, and especially in the CLI. Certain things would fail with it. The situation is much better in the latest @angular/compiler and Angular CLI versions, so, I suggest you try a new version and see.
npm uninstall --global angular-cli npm cache clean npm install --global angular-cli
After that you can go to your existing project and run ng init
, or try ng new some-new-folder
, and copy your files there.
Then run ng build -prod --aot
and see if you get errors you can fix (sometimes it asks for specific things), or if not, please create a new question with specific error.
P.S.
The only command that does not support AoT is ng github-pages:deploy
, if you use it, you can use ng github-pages:deploy --skip-build
, and run ng build -prod --aot
before you call it.
Upvotes: 1