javascript - After converting es6 to es5 using webpack, how can I call the previously packaged code in es5?
大家讲道理
大家讲道理 2017-05-19 10:14:10
0
1
495

es6 code test.js

class test {
  constructor() {
    console.log("init");
  }
}

module.exports = test;

index.html

<!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.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
左手右手慢动作

Inside the configuration of

webpack

output.libraryTarget set to 'umd'

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template