I'm having a bit of trouble with contexts in requireJS. What I'd like to is create a context, "mycontext", at the config stage (before I load any modules), and then have that context kept throughout. This is complicated because I am unfortunately required (<- ha!) to use the CommonJS syntax for my modules. So, if this is my base file looks like this:
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();
});
})();
Then, I load topModule:
http://www.example.com/src/topModule.js
define(['require', 'jquery', 'nestedModule'], function (require) {
var $ = require('jquery');
var other = require('nestedModule');
});
Will jQuery still be loaded only in mycontext? What if I go a level further:
http://www.example.com/src/nestedModule.js
define(function (require) {
var $ = require('jquery');
var oneMore = require('someOtherModule');
});
We already have access to jquery in this context, but will "someOtherModule" also be loaded in this context, or in the global "_" context? Is there any way to check if a module is already loaded before I make the require call?
Thanks!