0

我正在使用 Webpack 构建一个 JS 库并尝试导出一个对象。

import jwt_decode from "jwt-decode";

console.log(location.hash.replace('#', ''));

export var upstream = {
  user: {
    getUserDetails: () => {
      if (location.hash) {
        return jwt_decode(location.hash.replace('#', ''));
      } else {
        return null;
      }
    }
  }
}

在我的客户端代码中:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UpStream</title>
</head>

<body>
    <script src="http://localhost:8080/app.js"> <!--server is up, connects fine-->
    </script>
    <script>
        console.log(upstream);
    </script>
</body>

</html>

console.log();语句按预期工作,但我无法访问上游对象。任何指针?

4

1 回答 1

0

为了能够upstream通过window或仅访问,upstream您需要确保将导出指定为带有of的libraryTarget'window'

希望这会有所帮助!

于 2020-11-05T16:40:12.803 回答