У меня есть следующее ...
// src/index.mjs
class DoSomething{
constructor(){
console.log("Constructing");
}
doSomethingElse(){
console.log("Something else");
}
}
export { DoSomething };
// webpack config
const path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src/index.mjs'),
output: {
filename: 'sce-umd.js',
libraryTarget: 'umd'
},
module: {
rules: [
{
test: /\.mjs$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
}
Но когда я хочу использовать его в скрипте узла, я сначала должен объявить окно следующим образом ...
// WTF
global.window = global;
var DoSomething = require("../dist/sce-umd.js").DoSomething;
(function(){
var instance = new DoSomething();
instance.doSomethingElse();
})()
или же я получаю ...
ReferenceError: окно не определено
Итак, WTF?
(вот код)