Using backbone.localstorage with backbone boilerplate and require.js

362 views Asked by At

I'm using backbone boilerplate (grunt-bbb) and requireJS for a project and I have a question regarding backbone.localstorage and lodash. It seems like the localstorage plugin requires underscore. I've made an alias to backbone.localstorage in my apps config.js file:

paths: {
    "backbone-localstorage" : "./plugins/backbone.localStorage"
},

After I load backbone.localstorage into one of my modules, I get a 404 error on underscore.js. I am assuming that this is because bbb uses lodash. So, I replaced lodash with the lodash.underscore.js file in the require.config.js file and everything worked:

var jam = {
    "packages": [

        // more packages here...

        {
            "name": "underscore",
            "location": "../vendor/jam/lodash",
            "main": "./lodash.underscore.min.js"
        }
    ],
    "version": "0.2.11",
    "shim": {
        "backbone": {
            "deps": [
                "jquery",
                "underscore"
            ],
            "exports": "Backbone"
        },
        "backbone.layoutmanager": {
            "deps": [
                "jquery",
                "backbone",
                "underscore"
            ],
            "exports": "Backbone.LayoutManager"
        }
    }
};

My question is, was this the right way to do this? Should I have done this in my config.js file and then loaded underscore as a module?

0

There are 0 answers