requirejs Getting started with requirejs Incorporating Non-AMD Libraries

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Not all libraries are defined in a way that is compatible with AMD and RequireJS's define() function. The author's have addressed this by including a shim directive for configuring those dependencies.

One example is using the jQuery UI Layout Plugin. That plugin depends on jQuery. You can configure it like this:

requirejs.config({
    paths: {
        'jquery': '../path/to/jquery.min',
        'jquery.layout': '../path/to/jquery.layout.min'
    },
    shim: {
        'jquery.layout': {
            deps: ['jquery']
        }
    }
});

And then use it in a layout module like this:

define(['jquery', 'jquery.layout'], function ($, layout) {
    $('body').layout();
});


Got any requirejs Question?