From b7762987f7dbf3dd6a8b63fff1c1c40ed5966ac8 Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Tue, 30 Jun 2015 11:00:24 -0400 Subject: [PATCH] Support CommonJS and fix UMD I'm using this library with Browserify and found that it was unable to detect d3 correctly. This adds in the necessary `require` call to find the d3 dependency. I also changed the UMD signature to not expect that `define` and `require` are globals in the sense of the runtime, but instead are global within the encapsulating function scope (which may be the same as the runtime's). This will ensure d3.chart works as expected when bundled. --- src/wrapper/start.frag | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wrapper/start.frag b/src/wrapper/start.frag index e2032d6..30306e8 100644 --- a/src/wrapper/start.frag +++ b/src/wrapper/start.frag @@ -1,10 +1,12 @@ (function(global, factory) { "use strict"; - if (typeof global.define === "function" && global.define.amd) { + if (typeof define === "function" && define.amd) { define(["d3"], function(d3) { factory(global, d3); }); + } else if (typeof require === "function") { + factory(global, require("d3")); } else { factory(global, global.d3); }