Angular 2 个引导选项 - AOT 与 JIT
Angular 2 Bootstrapping Options - AOT vs JIT
刚刚开始 Angular 2.
angular 2 中有哪些不同的 Bootstrapping 选项?
为什么当我进行更改并刷新 index.html 时检索 HTML 标记的时间很短?
它们之间的区别
有两种选择
动态引导
- 编译器使用 JIT(及时)。
- 在浏览器中动态编译ts文件。
- 这就是 index.html 检索标记的时间很短的原因。
main.ts 包含以下
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
- 静态引导
- 编译器使用 AoT(提前)。
- ts文件编译成js文件,然后渲染到浏览器。
- 至此,一组包含模块和工厂的js文件通过使它们轻量级而在那里创建。
- 主要用于移动和传统网络。
main.ts 包含以下
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/app/app.module.ngfactory';
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
差异
在Angular中有两种编译方式
- JIT - 即时编译 AOT
- 提前编译
关于 JIT 与 AOT 编译,我想补充四个主要区别
|----------------------------------------|---------------------------------------------|
| JIT | AOT |
|----------------------------------------|---------------------------------------------|
| JIT compilation as the name implies, | AOT compilation compiles the application at |
| compiles the application Just in Time | build time |
| in the browser at runtime | |
|----------------------------------------|---------------------------------------------|
|For JIT compilation the browser needs to| AOT compilation it does not have to |
|download the angular compiler | |
|----------------------------------------|---------------------------------------------|
|While the application is being JIT | With AOT, the application is precompiled |
|compiled in the browser, users have | so there no such wait |
|to wait | |
|----------------------------------------|---------------------------------------------|
|With JIT compilation, the template | With AOT compilation we will come to |
|binding errors are only know at runtime | now about them at build time. |
|----------------------------------------|---------------------------------------------|
默认情况下,以下2个命令使用JIT编译
ng build
ng serve
使用这些命令中的任何一个,我们都可以使用 - -aot
选项来打开 AOT
ng build --aot
ngserve --aot
要关闭生产版本的 ACT,请将 - - aot
选项设置为 false
ng build -- prod --aot false
刚刚开始 Angular 2.
angular 2 中有哪些不同的 Bootstrapping 选项?
为什么当我进行更改并刷新 index.html 时检索 HTML 标记的时间很短?
它们之间的区别
有两种选择
动态引导
- 编译器使用 JIT(及时)。
- 在浏览器中动态编译ts文件。
- 这就是 index.html 检索标记的时间很短的原因。
main.ts 包含以下
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; platformBrowserDynamic().bootstrapModule(AppModule);
- 静态引导
- 编译器使用 AoT(提前)。
- ts文件编译成js文件,然后渲染到浏览器。
- 至此,一组包含模块和工厂的js文件通过使它们轻量级而在那里创建。
- 主要用于移动和传统网络。
main.ts 包含以下
import { platformBrowser } from '@angular/platform-browser'; import { AppModuleNgFactory } from '../aot/app/app.module.ngfactory'; platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
差异
在Angular中有两种编译方式
- JIT - 即时编译 AOT
- 提前编译
关于 JIT 与 AOT 编译,我想补充四个主要区别
|----------------------------------------|---------------------------------------------|
| JIT | AOT |
|----------------------------------------|---------------------------------------------|
| JIT compilation as the name implies, | AOT compilation compiles the application at |
| compiles the application Just in Time | build time |
| in the browser at runtime | |
|----------------------------------------|---------------------------------------------|
|For JIT compilation the browser needs to| AOT compilation it does not have to |
|download the angular compiler | |
|----------------------------------------|---------------------------------------------|
|While the application is being JIT | With AOT, the application is precompiled |
|compiled in the browser, users have | so there no such wait |
|to wait | |
|----------------------------------------|---------------------------------------------|
|With JIT compilation, the template | With AOT compilation we will come to |
|binding errors are only know at runtime | now about them at build time. |
|----------------------------------------|---------------------------------------------|
默认情况下,以下2个命令使用JIT编译
ng build
ng serve
使用这些命令中的任何一个,我们都可以使用 - -aot
选项来打开 AOT
ng build --aot
ngserve --aot
要关闭生产版本的 ACT,请将 - - aot
选项设置为 false
ng build -- prod --aot false