praekelt/sapphire — pull request #2 by justinvdm (2014-05-28 10:29:22+00:00)
Title: Add first dependencies

The first dependencies for sapphire will be:
- [d3](https://github.com/mbostock/d3)
- [d3-grid-layout](https://github.com/hughsk/d3-grid-layout)
- [strain](https://github.com/justinvdm/strain)

The biggest complication is adding these dependencies in a way that works for all cases, regardless of whether whoever is consuming sapphire is using amd, commonjs, or browser globals. Browserify adds a small wrapper for handling the different environments already (looks like people are calling it a ['umd'](https://github.com/forbeslindesay/umd) nowadays) if it is given a `standalone` option. Problem is, it doesn't handle dependencies for each environment, since it assumes everything will eventually be bundled together (dependencies included). This doesn't work for sapphire, since sapphire is meant to be another library people consume (so they might already be loading d3 on their page).

To solve this, the plan is to use [gulp-wrap](https://www.npmjs.org/package/gulp-wrap) to continue leaving the *defining* part up of the umd wrapping up to browserify, but handle the *dependencies* part by injecting the dependencies into a scope that all of sapphire's modules are contained in.

d3-grid-layout was designed to be included in browserify bundles, so it isn't registered as a bower component and doesn't do any umd wrapping. This is a tiny dependency, and it isn't likely that it will be around on pages already for people that want to use sapphire, so the plan is to bundle this dependency in with sapphire.