天天看點

Angular ngcc和ivy

Angular

項目的angular.json檔案裡有這麼一行:

Angular ngcc和ivy

“aot”: true,

意思是使用Ivy編譯, 即Angular 下一代編譯和渲染管道的代号。 從 Angular 的版本 9 開始,這個新的編譯器和運作時指令集就代替了老的編譯器和運作時(即視圖引擎 View Engine)成為了預設值。

可以使用通過 View Engine 編譯器建立的庫來建構 Ivy 應用程式。此相容性由稱為 Angular 相容性編譯器( ngcc )的工具提供。CLI 指令在執行 Angular 建構時會根據需要運作 ngcc.

如果你是庫作者,則應從版本 9 之後繼續使用 View Engine 編譯器。通過讓所有庫繼續使用 View Engine,你将與使用 Ivy 的預設 v9 應用程式以及已選擇的應用程式保持相容性。

ngcc即我們每次ng serve時看到的ngcc(worker):

Angular ngcc和ivy

The Angular ahead-of-time (AOT) compiler converts Angular HTML and TypeScript code into efficient JavaScript code during the build phase, before the browser downloads and runs that code. This is the best compilation mode for production environments, with decreased load time and increased performance compared to just-in-time (JIT) compilation.

By compiling your application using the ngc command-line tool, you can bootstrap directly to a module factory, so you don’t need to include the Angular compiler in your JavaScript bundle.

繼續閱讀