AMD(特别是RequireJ)如何处理多个模块之间的依赖关系 [英] How does AMD (specifically RequireJs) handle dependancies across multiple modules

查看:222
本文介绍了AMD(特别是RequireJ)如何处理多个模块之间的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的主要初始化脚本,该脚本调用require(),而依赖项之一是实用程序框架,但是我通过require()指定的其他一些模块本身也已将该框架定义为依赖项./p>

例如(init.js):

require(['module-a', 'module-b', 'module-c'], function(a, b, c){
    // where module-c is the framework
});

然后在模块-a"中,我有:

define(['module-c'], function(c){
    // utilize module-c framework
});

那么AMD/RequireJs如何处理这种情况,它会两次加载相同的框架吗?

任何帮助表示赞赏.

亲切的问候, 标记

解决方案

它将仅加载一次,以上两个模块都将为'module-c'获得相同的模块值.

I have my main initialization script which calls require() and one of the dependencies is a utilities framework, but some of the other modules that I'm specifying via require() also themselves have defined this framework as a dependency.

For example (init.js):

require(['module-a', 'module-b', 'module-c'], function(a, b, c){
    // where module-c is the framework
});

And then in 'module-a' I have:

define(['module-c'], function(c){
    // utilize module-c framework
});

So how does AMD/RequireJs handle this scenario, does it load the same framework twice?

Any help appreciated.

Kind regards, Mark

解决方案

It will only be loaded once, both of the above modules will get the same module value for 'module-c'.

这篇关于AMD(特别是RequireJ)如何处理多个模块之间的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆