I am attempting to implement an EXTREMELY basic test that uses jquery, underscore.js and backbone.js loaded via require.js and for some reason I just cannot seem to get everythi
Use optamd3 branch.
Feel free to have a look on the Modular Backbone.js Project Template which contains newest jQuery, Underscore, Backbone.js and RequireJS glued together .
I had the same problem. Actually I found that you do not need an AMD compliant Backbone or Underscore, or require-jquery or anything else (e.g. !order). All you need to do to is have app defined in paths and than set its dependencies in shim :). Somehow it used to work without it in the past.
paths: {
app:'app',
jquery: '../libs/jquery/jquery.1.9.1.min',
underscore: '../libs/underscore/underscore.min',
backbone: '../libs/backbone/backbone.min',
// ...
},
shim: {
"app": {
deps: ['jquery','underscore','backbone'],
exports: 'app'
},
"backbone": {
deps: ['jquery','underscore'],
exports: 'Backbone'
},
"underscore": {
exports: '_'
}
//...
}
I have actually spent a lot of time struggling with this same exact problem!
Here's how I have managed to get it working...
First off, download the new sample require-js project with jQuery 1.7. In the zip file you'll find a file called require-jquery.js which includes jQuery 1.7 which is now AMD compliant.
Then download the latest version of require, which is now also AMD, and last, try this version of Backbone...
https://github.com/jrburke/backbone/blob/optamd/backbone.js
Burke has created this off of a fork of backbone and made an AMD compliant version.
Then...
Index.htm
<!DOCTYPE html>
<html>
<head>
<title>Google Analytics API Browser</title>
<!-- This is a special version of jQuery with RequireJS built-in -->
<script data-main="main" src="require-jquery.js"></script>
</head>
<body>
</body>
</html>
main.js
require(['jquery','order!libs/underscore-min','order!libs/backbone','order!scripts/app'],
function($,_,Backbone,app){
app.init();
});
app.js
define(['jquery','backbone','scripts/home'], function($, Backbone, router){
var init = function(){
console.log("Started");
// In here you can load your routers/views/whatever
};
return { init: init};
});
My file structure looks like
/app/index.htm
/app/require-jquery.js
/app/order.js
/app/main.js
/app/text.js
/app/scripts/app.js
/app/scripts/home.js
/app/lib/underscore-min.js
/app/lib/backbone.js
Let me know if that helps, hit me up on twitter @jcreamer898 if you need some more help, I am literally working on the same stuff!
UPDATE I recently created a Github 2 github projects, one an actual app, and another just a simple starter...
https://github.com/jcreamer898/Savefavs
https://github.com/jcreamer898/RequireJS-Backbone-Starter
Here is an example of how to setup Backbone, lodash (Underscore replacement), jQuery, and Require: https://github.com/gfranko/Backbone-Require-Boilerplate