33
rated 0 times
[
38]
[
5]
/ answers: 1 / hits: 32468
/ 6 Years ago, mon, march 5, 2018, 12:00:00
According to the Webpack 4 documentation, if I specify libraryTarget: 'umd' it should result in the following output:
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports[MyLibrary] = factory();
else
root[MyLibrary] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return _entry_return_;
});
However, what I get is:
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define(lib, [], factory);
else if(typeof exports === 'object')
exports[lib] = factory();
else
root[lib] = factory();
})(window, function() {
return
To be more precise, instead of this
(typeof self !== 'undefined' ? self : this, function()
I get this:
(window, function()
This (obviously) causes runtime error window is undefined
when importing in node environment.
To be clear:
I know that window
doesn't exist in node applications. My question is not about this, but rather about webpack.
Is it a bug or am I missing something?
My output config:
output: {
path: resolve(__dirname, 'umd'),
filename: 'lib.js',
libraryTarget: 'umd',
library: 'lib',
umdNamedDefine: true,
},
More From » webpack