我应该如何生成app.module.ngfactory.ts文件?

use*_*495 3 angular

我试图将我的angular2应用设置为AOT。似乎为此app.module.ngfactory.ts需要一个文件,而不是app.module.ts用于JIT编译的标准文件。我正在app.module.ts为我的标准JIT应用程序工作。我该如何将该文件的内容转换为预期的格式app.module.ngfactory.ts

Max*_*kyi 5

您需要使用进行编译ngc。基本步骤是:

1)安装AOT编译器

npm install @angular/compiler-cli
Run Code Online (Sandbox Code Playgroud)

2)将配置添加到tsconfig.json

  "angularCompilerOptions": {
   "genDir": "aot",
   "skipMetadataEmit" : true
 }
Run Code Online (Sandbox Code Playgroud)

然后您可以运行ngc

node_modules/.bin/ngc -p tsconfig.json
Run Code Online (Sandbox Code Playgroud)

在输出aot文件夹中,您将看到app.module.ngfactory.ts文件。

您可以在此处了解更多信息。

  • 请注意,自Angular 5起,不再生成* .ngfactory.ts。 (3认同)