Requerir que JS aún no cargue el contenido de shim en orden

I maybe doing something obviously wrong here, this is the code i have and i keep getting an error saying _Packery is undefined and i presume that is because it is loading before jQuery.

I have looked at the docs but i couldn't see why it isn't working correctly.

require.config({
    urlArgs: "ts="+new Date().getTime(), // disable caching - remove in production
    paths: {
        jquery: [
            "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
            "libs/jquery-191"
        ],
        packery: [
            "plugins/packery"
        ]
    },
    shim: {
        'packery': ['jquery']
    }
});


require(['jquery', 'packery'], function($) {

    var container = $('#container');
    container.packery({
        itemSelector: '.item',
        gutter: 10
    });

});

Any help that allows me to understand what i have done wrong would be appreciated.

Muchas Gracias

preguntado el 23 de abril de 13 a las 13:04

Please note that I have tried this same config setup with masonry and it works fine, so i don't know if this is just an issue with packery at the moment or just something else. Masonry is a suitable alternative for my needs -

2 Respuestas

I think u should define a shim like this:

 shim: {
        'packery': {
            deps: ['jquery'],
        }, ...

Then try to export packery like so...

require(['jquery', 'packery'], function($, packery) {

    var container = $('#container');
    container.packery({
        itemSelector: '.item',
        gutter: 10
    });

});

De documentación oficial: jQuery is not required to use Packery. But if you do enjoy jQuery, Packery works with it as a jQuery plugin.

Respondido 23 Abr '13, 13:04

thanks, i did try that from the require JS docs, but had no luck either - silbido

I think this may now be an issues with packery. I have just tried with masonry and it works fine. To note i did also try doing your edit. Thanks again! - silbido

Packery currently does not support AMD / Require JS. See https://github.com/metafizzy/packery/issues/20 However, this issue is in development and will be resolved in the future.

contestado el 11 de mayo de 13 a las 04:05

Isn't the point of shims to handle libraries that don't implement AMD? - máquina fantasma

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.