Search code examples
javascriptbackbone.jsrequirejsamd

Assign a "shortcut" for a module id in RequireJS?


I'm using Bower to manage dependencies for the client. Each javaScript file is in its own folder:

bower_components
|-- backbone
    |-- backbone.js
|-- jquery
    |-- jquery.js
|-- backbone.syphon
    | -- lib
         |-- amd
             |-- backbone.syphon.js 

Every time I need to define a view, I need to specify specify the full path to backbone.syphon.js:

define(['backbone.syphon/lib/amd/backbone.syphon', 'backbone'],
    function (BackboneSymphon, Backbone) {
        // View code
    }
);

Is there a way to define a "shortcut" (like shimming for Backbone) to a module?


Solution

  • Yes you can define it in paths config setting

    var require = {
      paths: {
        'backbone.syphon': 'backbone.syphon/lib/amd/backbone.syphon'
      }
    }