Reputation:
I am trying to wrap my head around dependencies in requirejs.
shim
, do I need to re-declare it when I define the module in that file?require
to load dependencies such as backbone, do I need to re-declare it when I define a module that is loaded as part of require
?Here's my code so far:
require.config({
//alias
paths: {
Backbone: 'libs/backbone-min',
Config: 'config',
Dom: 'dom',
App: 'app'
},
//dependencies
shim: {
'Backbone': ['libs/underscore-min'],
'Dom': ['libs/sizzle']
}
});
//used to load and use stuff
require(['Config','Dom','App','Backbone'], function(){
});
So in dom.js
can I just define a module using define(function(){...});
and start using Sizzle? Or do I still need to define it like this define(['libs/sizzle'], function(){...});
Also if I define a module in app.js, do I still need to load backbone in define
, since I already included it as part of require()
.
Upvotes: 5
Views: 5092
Reputation: 3288
1) If I already declared dependencies for a file using shim, do I need to re-declare it when I define the module in that file?
For every module you need to define it's set of dependencies.
2) If I use require to load dependencies such as backbone, do I need to re-declare it when I define a module that is loaded as part of require?
If you want to use backbone as dependency in arbitary modyle you could write
define(['backbone'], function(Backbone) { .. }
Upvotes: 1