我在 requireJS 中的上下文方面遇到了一些麻烦。我想要的是在配置阶段(在加载任何模块之前)创建一个上下文“mycontext”,然后始终保留该上下文。这很复杂,因为不幸的是,我需要(
base.js
contextReq = require.config({
context: 'mycontext',
baseUrl: 'http://www.example.com/src/',
paths:{
jquery: 'http://ajax.cdnjs.com/ajax/libs/jquery/2.0.3/jquery.min',
},
});
(function(){
contextReq(['require', 'topModule'], function(require, topModule){
topModule.initialize();
});
})();
然后,我加载 topModule:
http://www.example.com/src/topModule.js http://www.example.com/src/topModule.js
define(['require', 'jquery', 'nestedModule'], function (require) {
var $ = require('jquery');
var other = require('nestedModule');
});
jQuery 仍然只在 mycontext 中加载吗?如果我更进一步呢:
http://www.example.com/src/nestedModule.js http://www.example.com/src/nestedModule.js
define(function (require) {
var $ = require('jquery');
var oneMore = require('someOtherModule');
});
我们已经可以在此上下文中访问 jquery,但是“someOtherModule”是否也会在此上下文中加载,或者在全局“_”上下文中加载?在进行 require 调用之前,有什么方法可以检查模块是否已经加载?
Thanks!