javascript - How to access JS global variable in Typescript file, using webpack - Stack Overflow

If I have a global variable var x in my main.js file, which i'd like to be accessible in a typescr

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.

Share Improve this question asked Jul 12, 2017 at 11:23 rld001rld001 1531 gold badge3 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745578266a4634098.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信