Webpack generates the following UMD definition:
(function webpackUniversalModuleDefinition(root, factory) {
// this is CommonJS/Node
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
// this is AMD
else if(typeof define === 'function' && define.amd)
define([], factory);
// what is this environment or standard?
else if(typeof exports === 'object') <------------- ???
exports["rx-core-libs"] = factory();
// Window/Global
else
root["rx-core-libs"] = factory();
})
My question is what is this standard or environment for?
else if(typeof exports === 'object')
It's like CommonJS but without module
.
According to this comment by @sokra:
There are two different CommonJs specs. CommonJS strict has only exports and no module.exports. Node.js added module.exports but that's not part of the original spec.
This commonjs spec states that:
- In a module, there is a free variable called "exports", that is an object that the module may add its API to as it executes. Modules must use the "exports" object as the only means of exporting.
That's why webpack exports dependencies through exports
object:
else if(typeof exports === 'object')
exports["rx-core-libs"] = factory()