代码之家  ›  专栏  ›  技术社区  ›  Antony Sampath Kumar Reddy

在angular 2及以上版本中发出“ng build--prod”命令时,为什么生成块文件

  •  4
  • Antony Sampath Kumar Reddy  · 技术社区  · 6 年前

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

    当我想要将代码部署到服务器时,我需要通过发出以下命令来构建项目“ ng构建--生产 “正在生成如此多的区块文件。

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

    2 回复  |  直到 6 年前
        1
  •  7
  •   user4676340 user4676340    6 年前

    因为Angular是一个单页应用程序。

    这些块也是在您为应用程序提供服务时生成的。这是我的 ng serve 命令(无标志,仅服务):

    ** 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.   
    

    正如您所看到的,块也是在那里生成的。

    这些块表示纯Javascript代码。在这段代码中,您将找到您的样式、模板和所有角度特征(组件、服务…)。

    Angular使用这些块呈现动态页面。在引擎盖下,当你在水疗中心航行时,你实际上从未离开 index.html 页此文件的内容将被您的块替换。

        2
  •  5
  •   AntonioGarcía    6 年前

    这些块是由 webpack 它们用于将代码从服务器加载到浏览器。

    您可以在官方的Angular docs 在网页上。