Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tipped not playing well with Require JS

I'm working on a project which is using require js to incorporate a number of plugins. Tipped, however, does not play nice with require and was being marked as undefined once it was loaded, leading me to include manually in a script tag. The issue here though is that it doesn't like that either and was throwing a big horrible error about have an anonymous define module: http://requirejs.org/docs/errors.html#mismatch

This can be temporarily fixed by beautifying the "source" code and commenting out the initial line so that it is simply d.Tipped = c(jQuery), however I don't really like this approach. Can you suggest a better way of working with this, or a way of updating Tipped without stripping out the following?

"function" == typeof define && define.amd ? define(["jquery"], c) : "object" == typeof module && module.exports ? module.exports = c(require("jquery")) :

Comments

  • edited January 2016
    The code you mentioned is a UMD wrapper, basically boils down to the code below which is a common pattern for jQuery plugins. I guess it's tricky to configure RequireJS to work with jQuery plugins, try:

    http://stackoverflow.com/questions/10918063/how-to-make-a-jquery-plugin-loadable-with-requirejs
    // UMD wrapper
    (function(root, factory) {
    if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['jquery'], factory);
    } else if (typeof module === 'object' && module.exports) {
    // Node/CommonJS
    module.exports = factory(require('jquery'));
    } else {
    // Browser globals
    root.Tipped = factory(jQuery);
    }
    }(this, function($) {

    var Tipped = {
    create: function() {}
    // etc
    };

    return Tipped;

    }));
    The solution should be in the configuration of RequireJS itself, not in stripping out the UMD wrapper.
Sign In or Register to comment.