最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Create an Ahead-of-Time (AOT) compiled library to be consumed by Angular applications - Stack Overflow

programmeradmin3浏览0评论

I have an Angular 5 library that I expose as a package for other apps to consume from their node_modules.

Currently, the app is Just-in-Time(JIT) piled using rollup and gulp and exported as a package. So developer applications use my package in their JIT piled form.

Researching about AOT has led me to believe that any Angular app which when AOT piled is much more performant than its JIT counterpart on the browser. However, as a library developer, I would like to know if app developers will get any performance benefit if I were to expose my library AOT piled?

I use ng-bootstrap and a lot of other open-source libraries to create ponents in my module and add custom styling or functionalities on top of them. Do all the libraries I consume in my module also need to be in their AOT forms or I could use their JIT counterparts?

Also, I think it would be a good idea to have separate packages for my library - packageName and packageName-aot so that the users have an option to choose whichever library they want to use.

Apart from the entire code refactoring(changing the private variables used in the template to public, removing arrow functions, lambda expressions etc.), is there anything else I need to keep in mind before exposing my library modules in AOT form?

I cannot use the Angular CLI due to certain constraints, so will have to depend on @ngtools/webpack to get AOT pilation if any.

Currently, my tsconfig.json has the following options:

"angularCompilerOptions": {
    "skipTemplateCodegen": true,
    "strictMedtadataEmit": true,
    "fullTemplateTypeCheck": true
}

I have searched a lot on the internet, but the Angular AOT docs are pretty vague and are not very clear for what I have been trying to do here. Any sort of direction would be really helpful.
Thanks!

I have an Angular 5 library that I expose as a package for other apps to consume from their node_modules.

Currently, the app is Just-in-Time(JIT) piled using rollup and gulp and exported as a package. So developer applications use my package in their JIT piled form.

Researching about AOT has led me to believe that any Angular app which when AOT piled is much more performant than its JIT counterpart on the browser. However, as a library developer, I would like to know if app developers will get any performance benefit if I were to expose my library AOT piled?

I use ng-bootstrap and a lot of other open-source libraries to create ponents in my module and add custom styling or functionalities on top of them. Do all the libraries I consume in my module also need to be in their AOT forms or I could use their JIT counterparts?

Also, I think it would be a good idea to have separate packages for my library - packageName and packageName-aot so that the users have an option to choose whichever library they want to use.

Apart from the entire code refactoring(changing the private variables used in the template to public, removing arrow functions, lambda expressions etc.), is there anything else I need to keep in mind before exposing my library modules in AOT form?

I cannot use the Angular CLI due to certain constraints, so will have to depend on @ngtools/webpack to get AOT pilation if any.

Currently, my tsconfig.json has the following options:

"angularCompilerOptions": {
    "skipTemplateCodegen": true,
    "strictMedtadataEmit": true,
    "fullTemplateTypeCheck": true
}

I have searched a lot on the internet, but the Angular AOT docs are pretty vague and are not very clear for what I have been trying to do here. Any sort of direction would be really helpful.
Thanks!

Share Improve this question edited May 20, 2018 at 6:56 nashcheez asked May 18, 2018 at 22:32 nashcheeznashcheez 5,1831 gold badge30 silver badges54 bronze badges 2
  • I think you'd spend less time making your project work with angular-cli than rolling your own build. – elclanrs Commented May 18, 2018 at 22:34
  • @elclanrs I would if I could! :) – nashcheez Commented May 18, 2018 at 22:39
Add a ment  | 

1 Answer 1

Reset to default 9 +50

The library you write, and the libraries your library depends on, need to be AOT capable. That’s really all there is to it.

You do not write, and deliver, a library that is AOT piled (AOT piled form, as you put it); the consuming applications will do the AOT piling at build time.

All you must do is make sure that when a consuming application does an AOT build (ng build --prod if using the Angular CLI), that your library plays nice. By plays nice I mean, your library can AOT pile with the consuming app without blowing errors.

Library tools like generator-angular2-library, or ng-packagr (which is a tool the @angular/cli 6.0.0 uses to support building libraries) just build packages to JavaScript, nothing more.

It is up to the consuming application's build tool to do an AOT build. This is what allows a library to be used by any application (or application framework/library) that needs it. Try not to overthink what it takes to build/deploy a library. The heavy lifting of AOT is up to the application that uses it.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论