简体   繁体   English

Angular - AOT编译与ngc

[英]Angular - AOT Compilation ng vs ngc

What is different between AOT with ngc and rollup AOT与ngc和汇总之间什么不同

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

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

and AOT with Angular CLI 角度CLI的AOT

ng build --aot ng build --aot

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

both configuration is very different, which one is better or prefer. 两种配置都非常不同,哪一种更好或更喜欢。

When you run: 当你运行:

ngc -p tsconfig-aot.json

Angular runs AOT compiler against your files and produces a set of compiled files. Angular对您的文件运行AOT编译器并生成一组编译文件。 These files contain compiled factories for components and modules and are not bundled in any way. 这些文件包含组件和模块的已编译工厂,并且不以任何方式捆绑。 In order to be loaded into a browser they need to be bundled. 为了加载到浏览器中,需要捆绑它们。 And so this command: 所以这个命令:

rollup -c rollup-config.js

bundles them together into one bundle using rollup . 使用汇总将它们捆绑在一起成为一个捆绑包。 The && simply chains two commands. &&简单地链接两个命令。

When you run ng build --aot just as in the first case it runs AOT compiler against your files but instead of simply outputting them this compilation is part of webpack bundling process. 当你运行ng build --aot就像第一种情况一样,它对你的文件运行AOT编译器,但不是简单地输出它们,这个编译是webpack捆绑过程的一部分。 So the output is a webpack bundle. 所以输出是一个webpack包。

which one is better or prefer. 哪一个更好或更喜欢。

Since the general recommendation is to use webpack for applications and rollup for libraries, use the first configuration if you're building a library and the second for an application. 由于一般建议使用webpack进行应用程序和汇总库,因此如果要构建库而使用第一个配置,则应用第二个配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM