jquip
jquip copied to clipboard
Make jquip aware of CommonJS/AMD
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.