Search code examples
angulartypescriptangular2-aotangular-compiler-cli

Do the ngfactory files themselves have to be compiled in Angular 2 AOT compilation?


Whenever I compile an Angular 2 application with ngc, it creates the .ngfactory.ts files for every component and then compiles all the typescript to javascript.

However, when I run ´ngc´ the first time, it creates the ngfactory files, but compiles only other files to javascript. This means no compiled ngfactory javascript files are produced.

On second run, it does compile the ngfactory files too (probably because they were generated in the same folder as sources).

My question is: Are the ngfactories themselves supposed to be compiled or not? Does it affect the application in any way?


Solution

  • ngfactory files are already the compiled output, so you should not compile them again.

    It is best to specify a special directory for the ngfactory.ts files. Put this in your tsconfig.json

    "angularCompilerOptions": {
      "genDir": "compiled"
    }
    

    This will tell ngc to put the generated files into a compiled folder.