0

I have a file called "lib.jquery.js" (all libraries are starting with "lib." and not reusable application modules are starting with "app.") in my baseUrl directory, and a module definition:

define([
    "lib.jquery"
],
function(
    jQuery
){
    console.log(jQuery) // undefined
})

But jQuery here is undefined because jQuery module name is hardcoded inside it as "jquery" but not "lib.jquery". How do I configurate RequireJS correctly to make all loading modules check "lib.jquery" file when requesting "jquery" or force jQuery module to be named "lib.jquery"?

2 Answers 2

1

The jquery script defines the module as 'jquery' and expects that you will simply reference it as 'jquery'. This is done because one should not load 2 jquery files of different versions.

Workaround would be put the lib.*.js files into a separate directory called lib.

define(['lib/jquery'], function (jQuery) {

});
Sign up to request clarification or add additional context in comments.

Comments

0

I have found the solution here: Use requirejs and jquery, without clobbering global jquery?

  1. Renamed file lib.jquery.js to lib.jquery-core.js
  2. Created file lib.jquery.js with "jquery loader module":

    define(['lib.jquery-core'], function () { return jQuery.noConflict(true); });

Now it's working as intended to. Hardcoding names is evil.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.