how to use ahead-of-time compiler with angular cli webpack

[亡魂溺海] 提交于 2020-01-10 07:59:10

问题


is there a way to use AOT with angular cli?

I've installed the modules (@angular/compiler @angular/compiler-cli) and when I type ngc -p scr it creates the ngFactory.ts files and compiles it to dist/tsc-out (angular cli default in tsconfig)

not sure how to proceed from here :)

Cheers

Han


回答1:


All recent beta versions of the Angular CLI support AoT via the following:

ng serve --aot
ng build --aot
#and of course
ng build --prod --aot

Note: As of Angular CLI 1.0.0-beta.28 (released February 1st, 2017), --aot is on by default if --prod is specified.




回答2:


Angular-cli beta 17 now supports --aot :) !

See my tests on a brand new project (with nothing in it so) :

EDIT 1 : 28 november 2016 :
Since beta 21, AOT works with lazy loaded modules :) !
I gave some more details here : https://stackoverflow.com/a/40788258/2398593

EDIT 2 : 5 may 2017 :
The cli is compiling with AOT by default if you use --prod.
(since months but an upvote reminded me of that post !)

EDIT 3 : 27 July 2017 :
If you want to reduce your bundle size even more, it's now possible by running the build with --build-optimizer. On a small app, I went from 1.3Mb to 864Kb!



来源:https://stackoverflow.com/questions/39167600/how-to-use-ahead-of-time-compiler-with-angular-cli-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!