class test {
constructor() {
console.log("init");
}
}
module.exports = test;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>drawBoard</title>
</head>
<body>
</body>
<script type="text/javascript" src="../build/test.js"></script>
<script type="text/javascript">
console.log(typeof test) // undefined
</script>
</html>
Such a direct call will definitely fail.
I looked at the packaged code of webpack
, and my understanding is that an anonymous function is packaged, and then the class of module.exports
is returned in the anonymous functiontest
.
You can use import
to write with es6
, but how to call it with es5
?
Please explain, thank you.
Inside the configuration of
webpack
output.libraryTarget
set to 'umd'