首页 文章

Angular - AOT编译与ngc

提问于
浏览
1

有什么不一样 AOT with ngc and rollup

ngc -p tsconfig-aot.json && rollup -c rollup-config.js

https://angular.io/guide/aot-compiler#aot-quickstart-source-code

AOT with Angular CLI

ng build --aot

https://github.com/angular/angular-cli/wiki/build

两种配置都非常不同,哪一种更好或更喜欢 .

1 回答

  • 3

    当你运行:

    ngc -p tsconfig-aot.json
    

    Angular对您的文件运行AOT编译器并生成一组编译文件 . 这些文件包含组件和模块的已编译工厂,并且不以任何方式捆绑 . 为了加载到浏览器中,需要捆绑它们 . 所以这个命令:

    rollup -c rollup-config.js
    

    使用rollup将它们捆绑在一起 . && 只是链接两个命令 .

    当您运行 ng build --aot 时,就像第一种情况一样,它针对您的文件运行AOT编译器,但不是简单地输出它们,而是编译是webpack捆绑过程的一部分 . 所以输出是一个webpack包 .

    哪一个更好或更喜欢 .

    由于general recommendation是使用webpack进行应用程序和汇总库,因此如果要构建库而使用第一个配置,则使用第二个配置 .

相关问题