3

I'm just starting to use require.js and think it's great. However, I would like to use it as much as possible instead of dealing with <script> tags in my HTML files.

To that end, is it possible to work with a 3rd party library that doesn't have any define modules in it? This may be asking much I realize but is there a way to call...

require(["3rd_party"], function(3rd) {

});

...where 3rd_party.js is a script located in a js folder that require knows to look in? I know require has mapping libraries, things like require-jquery but wasn't sure if it's possible to use it out of the box with older utility libraries that weren't built with it in mind.

1 Answer 1

11

RequireJS 2.1.0 added the shim config element which allows using non-AMD 3rd party libraries like AMD modules. In your case it would be something like:

shim: {
    '3rd_party': {
        exports: '{the-global-name}' // what variable does the library
                                     // export to the global scope?
    }
}

This mechanism makes custom-build library wrappers like "require-jquery" pretty much obsolete.

More details in the RequireJS docs

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

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.