Can I generate input / declaration files (.d.ts) and decorator metadata (.metadata.json) with @ ngtools / webpack?

I am working on an Angular library, which I make compatible with AOT compilation. I ran it with some gulp tasks around ngc , but I would prefer to use @ngtools/webpack as it allows me a simpler method to use SASS and PUG for my styles and templates. However, I cannot find a way to get the declaration or metadata files from my virtual file system. Is there any way to emit these files?

+7
angular webpack angular-cli angular2-aot
source share
1 answer

For declarations you need to change the const lambda => export function.

it

 const declarations = () => [ Component ]; 

to

 export function declarations() { return [ Components ]; } 

then replace the tsc section in the scripts in your package. json using ngc .

Now from ( this comment on github )

All specified libraries must contain the .metadata.json file along with any .d.ts files that they create, otherwise they will not work correctly with ngc. The .metadata.json file contains the information we need that was in the source .ts file, but was not included in the .d.ts file. If we do not have this information, we will not be able to generate factories for the library.

  • So, make sure the _.metadata.json files are next to their associated *.d.ts files.

  • Since you are using webpack, you first need to use ngc , and then webpack on compiled code.


Image Sources 1. Create your Angular 2 library statically parsed for AoT
2. Getting your Angular 2 library for AoT

0
source share

All Articles