Skip to content

Instantly share code, notes, and snippets.

@alexbaulch
Last active August 29, 2015 14:05
Show Gist options
  • Save alexbaulch/7421aa4a8abf302d9b5a to your computer and use it in GitHub Desktop.
Save alexbaulch/7421aa4a8abf302d9b5a to your computer and use it in GitHub Desktop.
AMDify and CommonJSify your jQuery plugin! After spending ages trying to get a decent way to use jQuery plugins with Broswerify or RequireJS I found the following in Addy Osmani's UMD repo (https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js), completely hijacked, none of my own thinking or doing here but needed a way of finding thi…
// Uses CommonJS, AMD or browser globals to create a jQuery plugin.
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
$.fn.jqueryPluginCommonJs = function () {};
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment