dieulot/instantclick — pull request #104 by ThibWeb (2014-12-16 11:13:15+00:00)
Title: Add AMD (Require.js) + CommonJS (browserify) wrapper

Hi,

here's a PR to add support for two module loaders: Require.js (AMD modules, `define`) and browserify (Node-ish/CommonJS, `module.exports`). It should help with the following issues: #63 and #73.

The UMD wrapper is taken from https://github.com/eduardolundgren/gulp-umd (see also https://github.com/umdjs/umd). I changed it a little bit to accomodate the following [browserify issue](https://github.com/substack/node-browserify/issues/372) (use `window || this` for root instead of `this`).

The AMD / Require.js scenario is fully working, and I added a test case for it (http://127.0.0.1:8000/tests/?amd=1).

The CommonJS / browserify story is a little different. It's also fully working, but there are caveats:
- To take full advantage of CommonJS compatibility InstantClick would need to be available in npm: it means adding a `package.json`, and if possible publishing it on the npm repository. After that, users will be able to `require('instantclick')` instead of `require('../../vendor/instantclick-x.x.x/instantclick')`.
- Modules are statically bundled by browserify prior to being served on a page: a test case for browserify would need a build system in place, which is out of scope for this PR. On the flip side, I did tests on my computer and uploaded the resulting browserify bundle as [a gist](https://gist.github.com/ThibWeb/1c6ea5c6b87b623aa217). It works very well.

Let me know if it suits you!