我们正在将大型 ember 应用程序拆分为逻辑 block ,并延迟加载少数模块以提高性能。

我们有一个条目,它反过来递归地包含所有依赖项,并在构建过程中创建一个大的 rjs 优化文件。我们希望在初始加载期间加载一些核心组件和路由,并延迟加载其他所有组件。

我们希望将 require 调用嵌套在 route 中,并使用 beforeModelHook 加载本指南中指定的依赖 Controller 、模板、组件 http://toranbillups.com/blog/archive/2014/10/02/Lazy-loading-es6-modules-with-emberjs/

现在的问题是我们是否跳过 import 语句

import mycontroller = require("mycontroller") 

并使用嵌套的 require

beforeModel() { 
   require(["mycontroller"]) 
   ... 
} 

编译时,typescript 无法将 mycontroller 列为依赖项。如何解决这个问题?

还有哪些其他方法可以提高性能?

请您参考如下方法:

typescript fails to list mycontroller as dependency when compiled. How to resolve this issue

您需要使用文件的导入类型才能对模块具有运行时依赖性。这是专门为支持延迟加载场景而设计的

文档

此处介绍:https://basarat.gitbooks.io/typescript/content/docs/project/external-modules.html


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!