radar-chart-d3 icon indicating copy to clipboard operation
radar-chart-d3 copied to clipboard

Create default way to minify and add umd wrapper

Open jjoos opened this issue 9 years ago • 0 comments

Saw you reverted the module.exports, agree that that was probably the best to do, since it didn't support all use cases.

This pull request adds an umd wrapper, that should work with bower/amd/commonjs, more information in http://bob.yexley.net/umd-javascript-that-runs-anywhere/ .

I also added a standardized way to create the minified file, since it wasn't documented how to generate that file.

Github doesn't handle whitespace changes very smartly, so this is the actual diff to the radar-chart.js file, reproducible with this command: git diff --ignore-all-space dc53d2cb1682c37a35c6751a6363c08d244b4148

diff --git a/src/radar-chart.js b/src/radar-chart.js
index 33c71e7..f8291ee 100644
--- a/src/radar-chart.js
+++ b/src/radar-chart.js
@@ -1,3 +1,12 @@
+(function (root, factory) {
+    if (typeof define === "function" && define.amd) {
+        define(["d3"], factory);
+    } else if (typeof exports === "object") {
+        module.exports = factory(require("d3"));
+    } else {
+        root.RadarChart = factory(root.d3);
+    }
+}(this, function (d3) {
   var RadarChart = {
     defaultConfig: {
       containerClass: 'radar-chart',
@@ -372,3 +381,6 @@ var RadarChart = {
         .call(chart);
     }
   };
+
+  return RadarChart;
+}));

Minifying now works by running npm install && npm run minify.

jjoos avatar Dec 08 '15 11:12 jjoos