I'm new to working with Require.js and I've encountered a problem that I initially thought would be simple, but it's turning out to be quite challenging.
My goal is to create a global namespace for my Backbone application and load it as a module. Below is the code for my namespace (main.js):
define(
['jquery',
'underscore',
'backbone',
'GlobalRouter'
],
function($, _, Backbone) {
var App= {
Models: {},
Views: {},
Collections: {},
Routers: {},
init: function() {
new App.Routers.GlobalRouter();
Backbone.history.start();
}
}
return App;
});
Additionally, here is the content of my config.js file:
require.config({
// your configuration key/values here
baseUrl: "js",
paths: {
'jquery' : '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min',
'underscore': 'vendor/underscore-min',
'backbone': 'vendor/backbone-min',
'marionette': 'vendor/backbone.marionette',
'main' : 'main'
},
shim: {
'underscore': {
exports: '_'
},
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'main' : {
deps: ['underscore', 'jquery', 'backbone', 'GlobalRouter'],
exports: 'TEWC'
}
}
});
define([
'jquery',
'underscore',
'backbone',
'main'
],
function($, _, Backbone, App, GlobalRouter) {
console.log(App)
alert('hit ')
$(function() {
App.init();
});
}
;)
For reference, included below is the structure of my router:
define([
'jquery',
'underscore',
'backbone',
'main'
],
function($, _, Backbone, TEWC) {
TEWC.Routers.GlobalRouter = Backbone.Router.extend({
routes: {
"" : "index",
"documents/:id" : "edit",
"login" : "login"
},
edit: function(id) {
alert('edit')
},
index: function() {
alert('index')
},
login: function() {
alert('login')
}
});
});
I was previously encountering an error stating 'app is undefined'. Now, after a few minutes, I'm receiving a load timeout error which reads:
Uncaught Error: Load timeout for modules: main
Despite this, the alert isn't triggered and it seems like main.js is not being loaded. However, I suspect the router is loading since there are no errors regarding TEWC being undefined - could it be loading without appearing in the Network tab?
This may be a basic inquiry, does anyone have any insights on how to resolve this issue?