The definition of the UMD module can be summarized as follows:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'b'], factory);
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
// CommonJS
factory(exports, require('b'));
} else {
// Browser globals
factory((root.commonJsStrict = {}), root.b);
}
}(this, function (exports, b) {
//use b in some fashion.
// attach properties to the exports object to define
// the exported module properties.
exports.action = function () {};
}));
An issue arises with Chrome Extensions as they do not support these methods of exporting modules:
define
is unavailableexports
is not presentthis
does not refer towindow
This limitation results in UMD modules failing to export correctly into the window
object within a Chrome Extension environment. Is there a way to overcome this obstacle and successfully export a UMD module for use in a Chrome Extension?