1

I want to use Draw2D touch in an AMD environment. The library itself isn't AMD compliant but depends on some other - AMD compliant - libraries like Raphael and Shifty. So I set up a shim config for Draw2D (relevant parts included):

requirejs.config({
    paths : {
        // ...
        'shifty': 'lib/shifty',
        'raphael': 'lib/raphael',
        'draw2d': 'lib/draw2d-2.10.1.min'
    },
    shim: {
        // ...
        'shifty': {
            exports: 'Tweenable'
        },
        'raphael': {
            exports: 'Raphael'
        },
        'draw2d': {
            exports: 'draw2d',
            deps: ['jquery', 'Class', 'raphael', 'json2', 'canvg',
                   'rgbcolor', 'jquery.layout', 'jquery.contextmenu',
                   'jquery.touch_punch', 'jquery.autoresize', 'shifty',
                   'plugins-js', 'jquery.ui.custom']
        }
    }
});

Draw2D tries to access Raphael (and Shifty) globally:

function() {
    Raphael.fn.group
    ...
}

even with the shim config I'm getting ReferenceError because Raphael is not defined.

The question is basically, how to load a library which isn't AMD compliant but relies on AMD compliant libraries.

Akos K
  • 7,071
  • 3
  • 33
  • 46
  • You must not `shim` AMD compliant libraries (and you included shifty and raphael in your config). Specifying just the path is enough, shim is only needed for "old-style" libraries. Not sure if that's enough to fix your problem with draw2d, but hopefully it'll be a step in the right direction. – kryger Oct 31 '13 at 11:22
  • I realized that later reading the documentation, that `exports` and `init` have no effect for AMD compliant libraries, but removing those shim configs doesn't help either. – Akos K Oct 31 '13 at 15:35

0 Answers0