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'});
});

Critical dependency warning

Newer versions of webpack can show the following warning message when compiling, pointing to the ogma.min.js file:

Critical dependency: the request of a dependency is an expression

This warning is due to a line in Ogma that attempts to require optional dependency libraries: due to hybrid nature of the Ogma library, to run both in the client browser and in a NodeJS environment, there's an internal utility that normalize the different ways of requiring the dependencies. Webpack on his side prefers to have all the dependencies statically defined and showing a warning in case a dynamic require is used. This is of no harm for the user.