I have written a jQuery plugin using require, wrapped it in almond, and loaded it through a shim config in another app. Unfortunately, require is exposing the global jQuery to the plugin rather than the local one. My code:
plugin.js
(function() {
// almond code
// other dependencies
require(dependencies, function (dependencies) {
!function($) {
// window.jQuery == $ -> true
$.fn.plugin = function(options) { return this; }
}(jQuery);
});
})();
main.js
require.config({
paths: { 'jquery': 'vendor/jquery-1.9.1.min' },
shim: { 'plugin': ['jquery'] }
});
require(['jquery','plugin'], function ($) {
// window.jQuery == $ -> false
$('#plugin').plugin(options);
// error, object [Object object] has no method "plugin"
);
Shouldn't shim load the plugin code exposing the local jQuery module to the plugin's global scope?