All versions of this documentation
X

Integration with WebPack Download code

Ogma has some optional external dependencies to make some of its features work. The optional dependencies used by Ogma is the xlsx library (to export in the XLSX format).

Ogma fetches its optional external dependencies dynamically by looking at the global scope (window) or through require. If you're using Webpack there is a good chance that none of these methods will work for you:

  • Webpack avoids polluting the global (window) scope;
  • Calls to require are replaced at compilation. That's why Ogma does not call require directly: to avoid having to include heavy external libraries that may not be useful to the user

If you wish to use features that require external dependencies, you need to declare them by extending the Ogma.libraries object:

Ogma.libraries[moduleName] = library;

For example, this snippet of code load the xlsx library and export a small graph:

var Ogma = require('/path/to/ogma.min.js');

Ogma.libraries['xlsx'] = require('path/to/xlsx.min.js');

var ogma = new Ogma();

ogma.generate.random().then(function (graph) {
  return ogma.setGraph(graph);
}).then(function () {
  ogma.view.locateGraph();
  ogma.export.xlsx({filename: 'my-graph.xlsx'});
});