I would like to split up my libs and my app code in separate bundles so I can insert script tags for each separately since I don't want jQuery, Backbone and Underscore to be added to each of my apps bundles.
However, I've tried several ways of doing this and each time I get an error from Backbone saying:
Uncaught TypeError: Cannot read property 'ajax' of undefined
I'm compiling a libs.js file that looks like this:
global.$ = require('./jquery')
global._ = require('underscore')
global.Backbone = require('backbone')
I had to manually download jQuery and stuff it in my /src/vendor folder because nom install jquery just fails for some reason.
I also have some simple test app code that compiles to app.js:
// User.js
var Backbone = require('backbone')
module.exports = User = Backbone.Model.extend({
url : '/user'
});
// app.js
var User = require('./user');
var u = new User()
u.on('change', function(e){
$('h1').append('Updated!')
});
u.fetch()
In my HTML the script tag for libs.js precedes that of app.js.
Maybe I've just approached this whole thing in a weird way from the start, because there doesn't seem to be much helpful in the way of googling when it comes to using these libs in this way, so any input on this is greatly appreciated!