RequireJS - jQuery plugins with multiple jQuery versions

I am trying to port some obsolete js codes to modules so that they can be loaded using RequireJS.

I have three jQuery plugins, let them be called a, b and c.

  • Plugin a works with any version of jQuery
  • Plugin b works with jQuery version 1.4.2
  • The c plugin uses a and b and works with any version of jQuery.

Therefore, at any time when plugin a is required, the downloadable jQuery is version 1.4.2. My require.config looks something like this:

require.config({ paths:{ "jquery": "libs/jquery.1.9.1.min", "jquery1-4-2" : "libs/jquery1.4.2.min" }); 

And plugins are defined as follows:

 plugin a: define(["jquery"], function($){ (...) }); plugin b: define(["jquery1-4-2"], function($){ (...) }); plugin c: define(["jquery", "a","b"], function($){ (...) }); 

How can I configure this script so that if some plug-in needs a specific version of jQuery, while others do not require a version, then only this specific version is loaded?

Thanks in advance.

+6
source share
1 answer

If you are really using jquery 1.4, this version does not support Requirejs, you have to define the shim configuration, but you will have a conflict because jquery defines $ object globally, so it will overwrite any existing global $ variable. I think you can avoid this problem by using jQuery.noConflict.

-2
source

All Articles