本文介绍了RequireJs:如何界定第三方库额外的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我希望能够给其他之前先加载某些模块。例如,我想引导骨干之前先加载。我可以声明依赖像这样?
垫片:{
骨干:{DEPS:['引导']}
}
解决方案
没错,就是这样做(在程 require.config({...
当然块)。此外,还建议增加一个出口
键,将其设置为骨干
。这将允许你使用骨干在要求
或定义
块,就好像它是一个真正的AMD模块:
定义(['骨干'],功能(骨干){
//这里骨干是函数的参数,而不是全球参考
});
了解更多。事实上,他们甚至引用骨干为榜样!
Basically I want to be able to load some module first before other. For example, I want bootstrap to load first before backbone. Can I declare dependencies like so?
shim: {
'backbone': {deps: ['bootstrap']}
}
解决方案
Yes, that is the way to do it (in the require.config({ ...
block of course.) It is also recommended to add an exports
key and set it to Backbone
. This will allow you to use Backbone inside a require
or define
block, as though it were a real AMD module:
define(['backbone'], function (Backbone) {
// Backbone here is the function parameter instead of the global reference
});
Read more here. In fact they even reference Backbone as their example!
这篇关于RequireJs:如何界定第三方库额外的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!