Angular2,以较少的服务器调用加载模块

Angular2, Loading modules with less server calls

'import {ComponentHere} from "angular2"',这一个点击服务器,因此可能需要获取所有必需的文件。有什么方法可以减少对服务器的调用次数吗?

//localhost:9739/node_modules/@angular/common/src/directives/core_directives.js。 //localhost:9739/node_modules/@angular/common/src/pipes/uppercase_pipe.js”。 //localhost:9739/node_modules/@angular/common/src/forms/directives/control_container.js”。 等..

考虑使用 WebPack (https://angular.io/docs/ts/latest/guide/webpack.html) 它通常会减少发送给客户端的文件数量(但它们显然会更大)

您可以使用 "SystemJS Builder" (https://github.com/systemjs/builder) 并将其集成到 Gulp 之类的东西中,使其成为捆绑包构建过程的一部分。你给它一个入口点(你的应用程序),然后它会查看你的依赖树来构建你的包。

当你的包被使用时,systemjs 将从你的包中导入而不是每个小的 js 文件。当我使用 angular2 进行测试时,我在 DEV 中下载了 700 多个文件,而在使用该包时在 PROD 中只有 35 个。