I'm working with requirejs+jquery and i was wondering if there was a smart way to make a jQuery plugin work well with require.
For example i'm using jQuery-cookie. If i understood correctly i can create a file called jquery-cookie.js and inside do
define(["jquery"], // Require jquery
function($){
// Put here the plugin code.
// No need to return anything as we are augmenting the jQuery object
});
requirejs.config( {
"shim": {
"jquery-cookie" : ["jquery"]
}
} );
i wondered if i could do things like jQuery does, which is like this:
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
define( "jquery", [], function () { return jQuery; } );
}
or if this is the only way to make jQuery plugins compatible with requirejs or any amd
See Question&Answers more detail:os