I am trying to wrap my head around dependencies in requirejs.
- 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? - If I use
requireto load dependencies such as backbone, do I need to re-declare it when I define a module that is loaded as part ofrequire?
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().
For every module you need to define it’s set of dependencies.
If you want to use backbone as dependency in arbitary modyle you could write