Require.js shim, export the name myOwnGlobal

I'm not sure about using “export” in the shim configuration, following the example of the requireJS API, I can use the Backbone (B in capital letter) to export it to the global scope. This means that this will be a property of the window object. But I realized that I have to use this name, and I can’t export it with another link name, that is: "MyGlobalBackbone"

require.config({
  paths: {
    backboneAlias:'backbone'
  },
  shim : {
    backboneAlias : {
      deps : [ 'underscore', 'jquery-1.9.1' ],
      exports  : 'MyGlobalBackbone'
    }
  }
});

require(['backboneAlias'],function(backboneAsAliasDependency){
  console.log(backboneAsAliasDependency);//Loaded Ok
  console.log(MyGlobalBackbone); //Uncaught ReferenceError: MyGlobalBackbone is not     defined 
});

This code only works if I use "Backbone" instead of "MyGlobalBackbone" ...

+1
source share
3 answers

: shimming , . ( "Backbone" ) Backbone, , RequireJS shim config.

+7

API:
http://requirejs.org/docs/api.html#config-shim

:

// "Backbone" // .

, :

// use a global variable 'Backbone' that defined by the backbone vendor // .

0

map.

require.config({
  paths: {
    ...
  },
  shim : {
    ...
  },
  map: {
      '*': {
          'MyGlobalBackbone': 'Backbone'
      }
  }
});

MyGlobalBackbone Backbone (*) .

-1
source

All Articles