Stefano Maglione
Stefano Maglione

Reputation: 4150

Include library with require.js

I've added an external library spin.js to my project,built by require.js and backbone. I've added path in main.js:

require.config({
paths: {
jquery: 'libs/jquery/jquery-min',
underscore: 'libs/underscore/underscore-min',
backbone: 'libs/backbone/backbone',
templates: '../templates',
Handlebars: 'libs/handlebars/Handlebars',
codebird:'libs/codebird-js-develop/codebird',
oauth:'libs/oauth',
**spin:'libs/spin'**

}

});

require([

'app',

], function(App){


 App.initialize();
});

and called this library in a view,but console tells me that Spinner(function in library) is not defined:

define(["spin"],
function (spin) {}

Upvotes: 0

Views: 1175

Answers (1)

Indranil Mondal
Indranil Mondal

Reputation: 2857

After defining the paths try add a shim config like:-

shim: {
spin: {
  deps: ['jquery'],
  exports: 'spin'
}
}

I don't know whether spin.js requires jquery or not, it's just an example, but spin.js requires any other libray try to define that in dependency otherwise just define the exports.

Also check whether you're using the amd version of spin.js or not.

Upvotes: 1

Related Questions