Last Updated: February 25, 2016
·
3.074K
· flurin

Simplest requirejs jQuery.noConflict() wrapper

Because we often want to run jQuery in noConflict mode we have a simple wrapper module that returns the noConflict jQuery object.

define(["jquery-1.7"], function(){
  return jQuery.noConflict(true);
});

In the requirejs config looks like this:

requirejs.config({
  paths: {
    "jquery-1.7": ["//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min", "vendor/jquery-1.7.2.min"], // Don't use this one as a direct dependency! Use require-jquery
    "require-jquery" : "src/require-jquery"
  }
});

And we use the require-jquery module as a dependency wherever we use jQuery.