admin管理员组文章数量:1431024
If I have a global variable var x
in my main.js file, which i'd like to be accessible in a typescript file which is bundled by webpack into the same build/bundle.js, how would i go about this? I cannot access it directly as i assumed i might (them being in the same bundle at the end). I have read of export/import/require but cannot find how to apply this in the context of a webpack bundle.
If I have a global variable var x
in my main.js file, which i'd like to be accessible in a typescript file which is bundled by webpack into the same build/bundle.js, how would i go about this? I cannot access it directly as i assumed i might (them being in the same bundle at the end). I have read of export/import/require but cannot find how to apply this in the context of a webpack bundle.
2 Answers
Reset to default 4You may need to declare the variable in your typescript file so the piler knows its exists:
declare var x: any;
Adapted from this answer
ProvidePlugin from webpack should do the job, they have a pretty good example here
本文标签: javascriptHow to access JS global variable in Typescript fileusing WebpackStack Overflow
版权声明:本文标题:javascript - How to access JS global variable in Typescript file, using webpack - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745578265a2664464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论