Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make jquip aware of CommonJS/AMD #58

Open
IngwiePhoenix opened this issue May 2, 2015 · 0 comments
Open

Make jquip aware of CommonJS/AMD #58

IngwiePhoenix opened this issue May 2, 2015 · 0 comments

Comments

@IngwiePhoenix
Copy link

I just threw jquip into my system instead of jQuery...and straight away saw a problem:

    ;$['plug']("ajax", function ($) {

This line throws an "$.plug is not defined" error. The entire code is wrapped in these lines:

/* 2 */
/***/ function(module, exports, __webpack_require__) {
    /* WEBPACK VAR INJECTION */(function($) {

    // ... snip. Jquip goes in here.

    /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)))
/***/ },

The __webpack_require__(2) resolves to that very module. This can, but does not have to, happen. A solution would be to replace first or second line of jquip with this:

// Original
    window['$'] = window['jquip'] = (function(){

// Replace
    var $ = window['$'] = window['jquip'] = (function(){

This way, we gain these things:

  • A local reference to the object that we are building. Previously polluted $'s will be shaddowed by this one.
  • We can figure out if we have module.exports present and return jquip this way, too.

At the start or end of jquip:

if(typeof module != "undefined" && typeof exports != "undefined") {
    // "return" the jquip instance.
    exports = $;
}

I am not very familiar with AMD, but the first 20 lines of jQuery show a good example on how to go about them.

For now I have to fall back to jQuery, since there is no appearant way I can monkeypatch this problem out without having to fork this project ... for one line, at most.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant