Search code examples
requirejsamd

RequireJS module that extends another module


I'm using a project that has 2 different files wrapped in AMD which one extends the other, project is jsondiffpatch.

The project has 2 files (build/bundle.js and build/formatters.js) each export jsondiffpatch. When I include them in my file like:

define(['jsondiffpatch',
        'jsondiffpatch-formatters'], function (jsondiffpatch) {
});

the formatters extensions are not present. If I change the main config make jsondiffpath depend on the formatters like:

shim: {
    'jsondiffpatch': {
        deps: ['jsondiffpatch-formatters']
    }
}

I still don't get the formatters. This is a pretty common practice, but haven't seen to overcome it; i know its something simple, what am i missing?


Solution

  • This should work:

    shim: {
        'jsondiffpatch-formatters': {
            deps: ['jsondiffpatch'],
            exports: 'jsondiffpatch.formatters'
        },
        'jsondiffpatch': {
            exports: 'jsondiffpatch'
        }
    }