Retrieve your ngfactory, .metadata.json and .ngsummary.json with Angular 5

MacBook Pro on table beside white iMac and Magic Mouse

Since Angular 5 ang Angular CLI 1.5, Typescript files are no longer emitted on AOT compilation. Indeed, with Angular CLI 1.5, a new Webpack plugin arrived: AngularCompilerPlugin. This last is specially used when we compile an Angular 5 application. Previously, we used another Webpack plugin: AOTPlugin. The consequence is that the compiler no longer uses the genDir property and @ngtools/webpack keeps these intermediate files directly in memory. You can take a look at this discussion on Github for some explanations. So, with Angular CLI, there is no other output than the bundled files emit by Webpack.

Fortunately, we can retrieve your ngfactory, .metadata.json and .ngsummary.json and even more by an another way. The difference from Angular 4 to Angular 5 is that with Angular 4 the compiler only generated the extra code, i.e. ngfactory, ngsummary etc… but did not compile the developer’s code. ngc generated these files in gendir, and tsc generated the application files in src. With Angular 5, the compiler will output the entire code in JS file in the outDir folder specified in the compilerOptions section of your tsconfig.json.

You will understand, in order to generate your Angular factories, just launch the command:

./node_modules/.bin/ngc 

at the root of your project.

 

If you want to generate declaration files .d.ts, you can do this by setting declaration: true in the tsconfig.json file:

 

You get the following result:

 
Partagez
William KozaConsultant Indépendant chez  Passionné par la conception et le développement logiciel, j’ai rapidement pris le rôle de Technical Leader lors de mes premiers projets. Ces expériences ont ainsi pu me faire accéder à des rôles d’architecte dans des projets d’envergure. Aujourd’hui, j’exerce mon métier en tant qu’indépendant, et toujours avec la même passion. Les derniers articles par William Koza (tout voir)

Publié dans Tips & TricksÉtiqueté Angular, Angular-CLI, AOT, compiler, ngfactory

Laisser un commentaire