简体   繁体   English

带有requirejs的Typescript惰性加载余烬模块

[英]Typescript lazy load ember modules with requirejs

We are in process of splitting our large ember app into logical chunks and delay load few of the modules to improve performance. 我们正在将大型余烬应用拆分为逻辑块,并延迟加载几个模块以提高性能。

We have an entry which in turn recursively includes all dependencies and creates one big rjs optimized file during build process. 我们有一个条目 ,该条目又递归包括所有依赖 ,并在构建过程中创建了一个大的rjs优化文件。 We want to load few core components and the routes during initial load and delay load everything else. 我们希望在初始加载期间加载少量核心组件和路由,而在其他所有加载过程中延迟加载。

We want to nest our require calls inside route and use beforeModelHook to load dependent controllers, templates, components as specified in this guide http://toranbillups.com/blog/archive/2014/10/02/Lazy-loading-es6-modules-with-emberjs/ 我们希望将我们的require调用嵌套在路由中,并使用beforeModelHook加载本指南中指定的依赖控制器,模板,组件http://toranbillups.com/blog/archive/2014/10/02/Lazy-loading-es6-modules -with-emberjs /

Now the problem is if we skip import statement 现在的问题是,如果我们跳过导入语句

import mycontroller = require("mycontroller")

and use nested require 并使用嵌套的require

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

typescript fails to list mycontroller as dependency when compiled. 编译时,打字稿无法将mycontroller列为依赖项。 How to resolve this issue? 如何解决这个问题?

What are other ways of achieving improving performance? 还有什么其他方法可以提高绩效?

typescript fails to list mycontroller as dependency when compiled. 编译时,打字稿无法将mycontroller列为依赖项。 How to resolve this issue 如何解决这个问题

You need to use the imported type for your file to have a run-time dependency on the module. 您需要为文件使用导入的类型,以对模块具有运行时依赖性。 This is specifically designed to support lazy loading scenarios 这是专门为支持延迟加载方案而设计的

Docs 文件

This is covered here : https://basarat.gitbooks.io/typescript/content/docs/project/external-modules.html 在这里介绍: https : //basarat.gitbooks.io/typescript/content/docs/project/external-modules.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM