PatrickJS-starter icon indicating copy to clipboard operation
PatrickJS-starter copied to clipboard

Ahead of time (AOT) compilation support

Open itrethan opened this issue 10 years ago • 75 comments

Note: for support questions, please use one of these channels: Chat: AngularClass.slack or Twitter: @AngularClass

  • I'm submitting a ... [ ] bug report [x ] feature request [ ] question about the decisions made in the repository
  • Do you want to request a feature or report a bug? Request a feature, AOT support in webpack
  • What is the current behavior? JIT compile, performance is bad in prod.
  • What is the motivation / use case for changing the behavior? Performance boost

itrethan avatar Aug 23 '16 08:08 itrethan

I agree, we should use AOT compilation now that it's available in Angular2!

IAMtheIAM avatar Aug 23 '16 21:08 IAMtheIAM

+1

unsafecode avatar Aug 25 '16 08:08 unsafecode

there's still a lot of bugs and peculiarities in aot that would break most people's app...so this doesn't need to be added immediately

qdouble avatar Aug 25 '16 11:08 qdouble

At least we can get a writeup explaining how to do it individually, so we can work the kinks out ourselves.

IAMtheIAM avatar Aug 25 '16 15:08 IAMtheIAM

The details could be found here: http://blog.mgechev.com/2016/08/14/ahead-of-time-compilation-angular-offline-precompilation/

Just wondering how to do that with webpack, maybe another loader?

itrethan avatar Aug 25 '16 20:08 itrethan

+1

Spittal avatar Sep 06 '16 04:09 Spittal

I was finally able to get AOT running fine with Webpack 2, you guys can check it here: https://github.com/qdouble/angular2webpack2-starter . There is a known issue with lazy routes when using AOT though, hopefully they patch it soon https://github.com/angular/angular/issues/11075

qdouble avatar Sep 06 '16 14:09 qdouble

@qdouble I downloaded your repo and got it to compile, excellent!. Only problem is, it doesn't work with any require() statements, like used in most webpack apps. When I try to get it working with require(my.template.html) inside a component, it just gives error:

Error: Error encountered resolving symbol values statically. Calling function 'require', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function,

IAMtheIAM avatar Sep 06 '16 18:09 IAMtheIAM

@IAMtheIAM that's an AOT limitation. You can't use require on your styles or templates with offline compile. It should work fine with JIT. For your html and styles, use templateUrl and stylesUrls... they will be bundled properly because the starter is using the angular2-template-loader.

qdouble avatar Sep 06 '16 19:09 qdouble

I've updated my starter project to fully support lazy loading in AOT mode. I have to wait until there are some more updates/bug fixes before making it a bit cleaner, but it's a viable solution for now: https://github.com/qdouble/angular2webpack2-starter/pull/3

qdouble avatar Sep 07 '16 12:09 qdouble

+1

Enlcxx avatar Sep 22 '16 21:09 Enlcxx

@qdouble any updates on this ?

kodeine avatar Sep 27 '16 05:09 kodeine

@kodeine uh, my angular repo has grown and is working very well, but I'm not trying to say anything negative about this repo... my link is here: https://github.com/qdouble/angular2webpack2-starter address any issues there.

qdouble avatar Sep 27 '16 06:09 qdouble

+1. AOT very important to increase speed for first start. We have big app on angular2 and we have first init time about 2-3 sec. after 1 sec of loading. 4 seconds is not good for reactive apps. Thanks.

breslavsky avatar Oct 02 '16 17:10 breslavsky

@qdouble I think, you should make more production-ready config for webpack. I mean splitting different environments ti dedicated files. Now your webpack config is unsupportable and not ready to be usen in production.

vadjs avatar Oct 12 '16 10:10 vadjs

@vadimzham I disagree, it's a matter of preference I suppose.

qdouble avatar Oct 12 '16 12:10 qdouble

@qdouble Dedication configs on production/staging/development environments it's not just preference. It's necessity.

vadjs avatar Oct 12 '16 15:10 vadjs

@vadimzham that's really just your opinion. There's no major difference between a production and development config that can't be solved with pushing in a few extra plugins or changing some settings based on variables. It's a design choice.

qdouble avatar Oct 12 '16 16:10 qdouble

It would be great if we can incorporate tree shaking into the prod AOT build process as well.

https://angular.io/docs/ts/latest/cookbook/aot-compiler.html#!#tree-shaking

sbehun avatar Oct 12 '16 18:10 sbehun

@vadimzham We are already using the webpack starter of @qdouble in production.

Have a look at this sexy & fast website :-) https://secrets.schmid.digital

It uses AoT and is ultra fast. The website is now about 4-5x faster than before! Thanks again to @qdouble . He does awesome work! :)

Check out this webpack starter, if you can't wait longer to use AoT! https://github.com/qdouble/angular-webpack2-starter

smyth64 avatar Oct 12 '16 20:10 smyth64