[英]How can I lazy load routes using Webpack?
I migrated our application from SystemJS to Webpack with pretty good results except that I'm unable to get lazy routes to work. 我将我们的应用程序从SystemJS迁移到Webpack,结果非常好,除了我无法获得惰性路由。
The error I keep getting is Uncaught (in promise): ReferenceError: System is not defined
. 我一直收到的错误是
Uncaught (in promise): ReferenceError: System is not defined
。 The error occurs in both vendor and polyfill generated JS files. 该错误在供应商和polyfill生成的JS文件中均发生。
I tried adding a custom System
typing taken from the Webpack starter kit - 我尝试添加从Webpack入门套件中获取的自定义
System
类型-
interface SystemJS {
import: (path?: string) => Promise<any>;
}
declare var System: SystemJS;
I tried using Node's es6-promise
package from this - 我试图使用节点的
es6-promise
包从这个 -
{ path: 'my', loadChildren: () => require('es6-promise!./my/my.module')('MyModule') }
Other than that, I haven't been able to find any other alternatives. 除此之外,我还找不到其他选择。 Unfortunately, the official Angular 2 documentation leaves much to be desired when it comes to supporting Webpack.
不幸的是,当涉及到支持Webpack时,Angular 2官方文档还有很多不足之处。
I'm using the final version of Angular 2 and the router v3. 我正在使用Angular 2和路由器v3的最终版本。
There is a webpack loader from brandon roberts: https://github.com/brandonroberts/angular2-router-loader 有一个来自brandon roberts的webpack加载器: https : //github.com/brandonroberts/angular2-router-loader
Or you could use the angular-cli
which has built in support. 或者,您可以使用内置支持的
angular-cli
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.