AMD support

jeroenh's Avatar

jeroenh

20 Jun, 2013 08:23 PM

Hi,

I would very much like support for AMD modules and script loaders. It should be very straightforward to support both AMD and non-AMD usage:

https://github.com/umdjs/umd/blob/master/jqueryPlugin.js

Jeroen

  1. Support Staff 1 Posted by Dmitry Semenov on 20 Jun, 2013 09:17 PM

    Dmitry Semenov's Avatar

    Hi,

    Thank you for suggestion, added this to roadmap, but cannot promise that feature will be added very soon.

    Dmitry

  2. 2 Posted by pesche on 26 Jun, 2014 12:35 PM

    pesche's Avatar

    Are there any updates on this? It would make it much easier to use your plugin with tools like requirejs or browserify.

  3. Support Staff 3 Posted by Dmitry Semenov on 26 Jun, 2014 01:27 PM

    Dmitry Semenov's Avatar

    @Pesche, you may just wrap contents of js file with:

    !function(root, factory) {
        if (typeof define === 'function' && define.amd) {
            define(['jquery'], factory);
        } else {
            factory(root.jQuery);
        }
    }(this, function($) {
        'use strict';
    
        // contents
    
    });
    
  4. 4 Posted by hello on 09 Mar, 2016 12:41 AM

    hello's Avatar

    Hi Dimitry,

    I'm having trouble with importing RoyalSlider via ES6 imports and Browserify.. This is my code

    import $           from 'jquery';
    import royalSlider from 'royalslider/jquery.royalslider.min.js';
    

    Although I'm receiving the following error in the console
    `jquery.royalslider.min.js:61 – Uncaught ReferenceError: jQuery is not defined

    I've tried changing import $ to import jQuery and it's still not working.

    Any ideas?
    Thanks

  5. Support Staff 5 Posted by Dmitry Semenov on 09 Mar, 2016 10:27 AM

    Dmitry Semenov's Avatar

    @Jake, have you tried also adding:

    import jQuery from 'jquery'
    

    ?

    or like this:

    import $ from 'jquery'
    import jQuery from 'jquery'
    window.$ = $;
    window.jQuery = jQuery;
    
    // ...
    
  6. 6 Posted by hello on 09 Mar, 2016 10:34 AM

    hello's Avatar

    Hi Dmitry,

    Yes I've tried both of your suggestions and still getting error Uncaught ReferenceError: jQuery is not defined.

    Any other ideas?

  7. Support Staff 7 Posted by Dmitry Semenov on 10 Mar, 2016 03:30 PM

    Dmitry Semenov's Avatar

    Do you get jQuery version printed when you execute such code?

    import $ from 'jquery'
    import jQuery from 'jquery'
    window.$ = $;
    window.jQuery = jQuery;
    
    console.log( jQuery.fn.jquery );
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac