来自 Angular-CLI documentation在下面,我无法收集“有限”摇树或消除死代码的含义。这是否意味着我们不应该依赖 angular-cli 提供的 tree-shaking 和死代码消除抽象?
捆绑和 Tree-Shaking
所有构建都使用捆绑和有限 tree-shaking,而 --prod 构建还通过 UglifyJS 运行有限死代码消除。
另一个文档问题 似乎 --prod 为 free 提供了 --aot 标志.这意味着如果您的构建是 --prod,则代码会预编译到 Javascripts 中。但是,从 -aot 特定文档(在下面引用)看来,默认的 aot 标志似乎是 false。对这些标志有任何经验吗?
aot --aot 默认值:false
最佳答案
我最近有同样的问题,所以这是我的研究结果。
Tree-shaking删除依赖项注入(inject) (DI) 定义的依赖项。
Tree shaking refers to a compiler option that removes code from the final bundle if that code not referenced in an application.
dead code elimination UglifyJS 执行的是一个后处理步骤,用于删除无法访问的代码(例如,返回后的代码)。
dead_code (default: true) -- remove unreachable code
从 Angular CLI 6 开始,构建系统已经过彻底改造,更易于配置。 Build configuration选项已移至工作区配置文件 (angular.json)。
A "production" configuration is created by default when you use the CLI to create the project, and you can use that configuration by specifying the --prod option.
默认开发环境和生产环境之间的区别在于,开发配置使用 CLI 默认设置(例如源映射),而生产配置启用 AOT、优化等。--prod 元标志针对“生产”配置并启用 runtime production mode .
Switching to production mode makes it run faster by disabling development specific checks such as the dual change detection cycles.
关于angular - angular-cli 文档中的 tree shaking 和死代码消除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46158543/