0

A am relatively new to JamJS, and struggle to make it work properly. I've got a very simple project based on Backbone and RequireJS, where I use JamJS to manage dependencies, namely: Backbone, _, Less, $, modernizr, underscore, bootstrap.

I tend to follow the method used by Backbone Boilerplate.

This is the code I use to get the Jam-compiled requireJS config file, together with my application-specific require config:

in html:

< script data-main="/assets/js/app/config" src="/assets/js/jam/compiled.min.js"> < /script>

'Compiled.min.js' is obviously the 600kb minified file generated by Jam. The '/app/config' file is my Require.js configuration file where I'm planning to include all my project-specific code, not managed by the dependency manager.

Here's app/config.js:

require.config({
  baseUrl:'/assets/js/',
  deps: ['less','modernizer','bootstrap-jam','app/main'],
  paths: {
    'homeView': 'app/views/homeView'
    // Use the underscore build of Lo-Dash to minimize incompatibilities.
    ,'lodash': '../jam/lodash/dist/lodash.underscore.min'
  },
  map: {
  },
  shim: {
  }
});

(the files in deps are the ones I need on every page + my main.js - kind of a router.

The problem is that, in my homeView (which is initialized by main.js), I do this sort of thing:

define(['backbone'], function (Backbone) {
    return Backbone.View.extend({
        el:$('#homepageWrapper'),
        initialize: function () {
            this.$('#subTitle').text('This text is generated by homeView - the     default Backbone View.');
        }
    })
});

As you can see I want Backbone to be available in this view. I assume that it's available through the compiled Jam code, however when I look in the Network panel in the Web Inspector, I see that this dependency is pulled in separately- this happens to any resource I try to use, not just Backbone.

I suspect that it might be something to do with the error I get as well, which I haven't been able to figure out. When using the compiled jam config, I get:

Uncaught Error: Module name "underscore" has not been loaded yet for context: _. Use require([])

I'd really appreciate help with this

Thanks.

Klon
  • 445
  • 1
  • 5
  • 13
  • I'm not familiar with JamJS, but in general you need to set up a RequireJS shim config so that it knows to load lodash first before returning your Backbone reference. Also possibly related: https://github.com/caolan/jam/issues/117 – explunit Jun 11 '13 at 14:04
  • possible duplicate of: http://stackoverflow.com/questions/14104835/requirejs-how-specify-shim-dependency-from-jam-file-package-section – explunit Jun 11 '13 at 14:11
  • Thanks for your suggestions, but the solutions given in the issues you referred to are not applicable for my problem, unfortunately. I am compiling the Jam dependencies, only then I'm facing the described problem. Using regular not-compiled code works, but the most valuable thing about having Jam is that it can compile and minify all packages into one module. in my case, eventhough it does it, it still pulls for modules afterwards. – Klon Jun 11 '13 at 15:37

0 Answers0