I'm trying to use the rangy npm package in a project, but when webpack attempts to build our script(s), the AMDdefine() function is being called:
(function(factory, root) {
if (typeof define == "function" && define.amd) {
console.info('why is this called?');
console.info(define);
console.info(define.amd);
// AMD. Register as an anonymous module.
define(factory);
} else if (typeof module != "undefined" && typeof exports == "object") {
// Node/CommonJS style
module.exports = factory();
} else {
// No AMD or CommonJS support so we place Rangy in (probably) the global variable
root.rangy = factory();
}
})...
This is the output in the Firefox console:
However, webpack executes in a CommonJS/ES6 environment, so if I comment out the "AMD" portion of the if-statement above, the CommonJS code is executed.
(function(factory, root) {
// if (typeof define == "function" && define.amd) {
// console.info('why is this called?');
// console.info(define);
// console.info(define.amd);
// // AMD. Register as an anonymous module.
// define(factory);
// } else if (typeof module != "undefined" && typeof exports == "object") {
if (typeof module != "undefined" && typeof exports == "object") {
console.info('now we are node!');
// Node/CommonJS style
module.exports = factory();
} else {
// No AMD or CommonJS support so we place Rangy in (probably) the global variable
root.rangy = factory();
}
})...
My guess is that this is a webpack incompatibility problem, but perhaps changing the order of evaluation in the if-block across all rangy modules would be a simple fix for this.
I'm trying to use the rangy npm package in a project, but when webpack attempts to build our script(s), the AMD
define()
function is being called:This is the output in the Firefox console:
However, webpack executes in a CommonJS/ES6 environment, so if I comment out the "AMD" portion of the if-statement above, the CommonJS code is executed.
My guess is that this is a webpack incompatibility problem, but perhaps changing the order of evaluation in the if-block across all rangy modules would be a simple fix for this.