Webpack构建打字稿后无法访问全局命名空间

时间:2018-06-27 15:50:51

标签: javascript typescript webpack namespaces

我是第一次尝试。基本上,我有一些基于TypeScript的库,它们提供了分层结构中共享组件的功能。

例如包含需要在不同模块之间共享的“ Costants”和“ Enums”的示例,这些模块可以根据用户订阅进行动态加载。

因此,我编写了一个名为AppShared的程序包并导出NameSpace。 (它将根据打字稿名称空间文档将其附加到Windows),可以正常工作,就像我可以console.log(EmtShared);并在html页面中查看该值。

但是问题是,如果我将其导入其他模块并在webpack配置中将其声明为“外部” ,则构建成功,但捆绑包中的Webpack会附加 n。,然后再访问它,此处 n未定义

有关如何解决它的任何线索。如果我不将其设置为外部,则webpack会将其捆绑在生成的结果中,这是我不希望的,因为此包需要由其他组件共享。

<body>
<script src="node_modules/@emt/infrastructure_shared/dist/index.js"></script>
<script>
    debugger;
 console.log(EmtShared); // accessible over here
</script>
<script src="node_modules/@emt/infrastructure_logger/dist/index.js"></script>
<script>
  var logger = new Emt.Logger();
  logger.log('hello', 'how are you?'); // in this function I am logging (EmtShared.AppConstants.Global.ADD_MESSAGE) which is not accessible after webpack build
</script>
</body>

在此处参考完整的存储库:https://github.com/CodeRowerSoftware/Emt-API-Infrastructure

https://github.com/CodeRowerSoftware/Emt-API-Infrastructure/blob/master/packages/Logger/webpack.config.js上的webpack配置

0 个答案:

没有答案
相关问题