HumbleSoftware / Flotr2

Graphs and Charts for Canvas in JavaScript.
http://www.humblesoftware.com/flotr2/
MIT License
2.45k stars 528 forks source link

Add build without 3rd party libs #225

Closed esamattis closed 11 years ago

esamattis commented 11 years ago

This build expects to find Underscore and Bean libraries as globals by the time it is loaded. This is very useful for those how want to take greater control of the libraries used.

Using this build RequireJS and Browserify users can manually setup a shim configs for Flotr2.

Here's something you might want to add to documentation:

Browserify Example

flotr2.shim.js

// Expose Underscore and Bean as globals from npm
window._ = require("underscore");
window.bean = require("bean");

// Require Flotr2 expecting the globals
require("./flotr2.nolibs");

// Export it as a module for convenience
module.exports = window.Flotr;

RequireJS Example

require.config({                                                                 
  shim: {                                                                       
    "flotr2": {                                                                                           
      deps: ["underscore", "bean"],                                              
      exports: "Flotr"                                                           
    },                                                                           
    "underscore": {                                                              
      exports: "_"                                                               
    }                                                                            
  },                                                                             
  paths: {                                                                       
    "flotr2": "vendor/flotr2.nolibs",                                           
    "underscore": "vendor/underscore",                                          
    "bean": "vendor/bean"                                                       
  }                                                                             
});

Bean is a AMD module so no need to shim it like Underscore.

cesutherland commented 11 years ago

Ah, cool!