Answer the question
In order to leave comments, you need to log in
How to organize a large number of dependencies in RequireJS?
I'm using RequireJS and ran into this problem:
define([ "require", "jquery", "blade/object", "blade/fn", "rdapi",
"oauth", "blade/jig", "blade/url", "dispatch", "accounts",
"storage", "services", "widgets/AccountPanel", "widgets/TabButton",
"widgets/AddAccount", "less", "osTheme", "jquery-ui-1.8.7.min",
"jquery.textOverflow"],
function (require, $, object, fn, rdapi,
oauth, jig, url, dispatch, accounts,
storage, services, AccountPanel, TabButton,
AddAccount, less, osTheme) {
});
Module = require('module')
User = require('user')
...
Answer the question
In order to leave comments, you need to log in
Your example is from the documentation, it also describes how to make it a little more readable
define(['require', 'dependency1', 'dependency2'], function (require) {
var dependency1 = require('dependency1'),
dependency2 = require('dependency2');
return function () {};
});
Personally, I describe dependencies for modules in the config at the requirejs entry point :
require.config({
// Описываем пути
baseUrl: '../js'
paths: {
jquery: 'libs/jquery',
someModule: 'module'
},
// Описываем зависимости для модулей
shim: {
someModule: ['jquery']
}
});
define(function(){
...
obj.someFunc = function(){
$("#someButton").click(...)
}
return obj;
});
define(
'blade',
['blade/object', 'blade/fn', 'blade/jig', 'blade/url'],
function(object, fn, jig, url) {
return {
object: object,
fn: fn,
jig: jig,
url: url
}
}
)
// …
define(
['blade', 'require', 'jquery'],
function(blade, require, jquery) {
// …
}
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question