Is it possible to do AOT compilation in Angular using only ES5?
More to the point, can I use the NGTools Webpack plugin with ES5?
I know TypeScript is the preferable language of choice for Angular, however my place of employment did not approve using TypeScript for our Angular project. My hands are a bit tied, and I don't want performance to suffer on the client due to this.
Some relevant info on my project:
I have looked all over and have not been able to find a clear answer on this, I would really appreciate any info anyone can provide.
Thanks in advance!
The Angular ahead-of-time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.
Just-in-Time (JIT) is a type of compilation that compiles your app in the browser at runtime. Ahead-of-Time (AOT) is a type of compilation that compiles your app at build time.
Faster rendering — With AOT, the browser downloads a pre-compiled version of the application. The browser loads executable code so it can render the application immediately, without waiting to compile the app first.
When you use the Angular AOT compiler, you can control your app compilation in two ways: By providing template compiler options in the tsconfig. json file. By specifying Angular metadata.
In you tsconfig.json file set the target to es5.
"target": "es5",
Angular is supposed to be fully ES5 compatible.
The AOT compiling process uses the metadata attached to components. This is how it finds the templates and styles that need compiling.
TypeScript is the preferred method for writing components. As it allows you to use the @Component
annotation function to attach metadata .
ES6 is secondary method and Angular supports ES6 decorators to attach metadata to components.
ES5 is more basic. There isn't any automatic way to attach metadata, but the AOT compiler will look for a annotations
array attached to the object's prototype.
This is how you would do it using ES5
HeroComponent.annotations = [
new ng.core.Component({
selector: 'hero-view',
template: '<h1>{{title}}: {{getName()}}</h1>'
})
];
So to answer your question. Yes, you can still use AOT with ES5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With