angular - 为什么在 Angular 2 及以上版本中发出 "ng build --prod"命令时会生成 Chunk 文件

标签 angular angular2-services chunks

目前正在使用高级 ui 框架(例如版本 2 和 4 的 Angular )实现我的用户界面代码。

当我想将代码部署到服务器时,我需要通过发出以下命令“ng build --prod”来构建项目,因此会生成许多 block 文件。

我想知道为什么会生成这些 block 文件。

最佳答案

因为 Angular 是单页面应用程序。

当您为应用程序提供服务时,也会生成这些 block 。这是我的 ngserve 命令的结果(没有标志,只是服务):

** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** 
Date: 2018-04-10T12:09:49.010Z                                                                               
Hash: 7e4a7d27b89ee3d81e37                                                                                   
Time: 15613ms                                                                                                
chunk {administration.module} administration.module.chunk.js () 9.22 kB  [rendered]                          
chunk {exploitation.module} exploitation.module.chunk.js () 1.26 MB  [rendered]                              
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]                                          
chunk {main} main.bundle.js (main) 625 kB [initial] [rendered]                                               
chunk {polyfills} polyfills.bundle.js (polyfills) 623 kB [initial] [rendered]                                
chunk {scripts} scripts.bundle.js (scripts) 562 kB [initial] [rendered]                                      
chunk {source-post.module} source-post.module.chunk.js () 1.42 MB  [rendered]                                
chunk {styles} styles.bundle.js (styles) 653 kB [initial] [rendered]                                         
chunk {vendor} vendor.bundle.js (vendor) 18.9 MB [initial] [rendered]                                        

webpack: Compiled successfully.   

如您所见, block 也在那里生成。

这些 block 代表纯 Javascript 代码。在此代码中,您将找到您的样式、模板以及所有 Angular 功能(组件、服务...)。

Angular 使用这些 block 来渲染动态页面。在幕后,当您在 SPA 上导航时,实际上永远不会离开 index.html 页面。该文件的内容将被您的 block 替换。

关于angular - 为什么在 Angular 2 及以上版本中发出 "ng build --prod"命令时会生成 Chunk 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49752929/

相关文章:

css - 向 Angular Material 工具提示箭头添加阴影

javascript - 解决 promise angular2 : Property 'includes' does not exist on type '[]'

r - 在 R 中流式处理大型 csv 文件

html - 如何播放来自 HTML5 websocket 的视频 block ?

javascript - ASP.NET Core - 运行多个 Angular 2 应用程序

go - 我可以在一台服务器上托管 Angular2 前端和 Golang 后端吗

angular - 关于angular2提供者的一些问题

angular - ts1109 : expression expected angular error

r - block 选项 class.output 不适用于错误消息

angular - 垫卡在我的 Angular 应用程序中不起作用