Can I use an ES6/2015 module import to set a reference in 'global' scope?

前端 未结 6 1175
温柔的废话
温柔的废话 2021-01-31 03:22

I have this situation where I am trying to import an existing library, which I\'ll call troublesome (using Webpack/Babel FWIW) and it has a global reference to

6条回答
  •  长情又很酷
    2021-01-31 03:58

    Shimming is fine and there are various ways of resolving this, but as per my answer here, the simplest is actually just to revert to using require for the loading of the library that requires the global dependency - then just make sure your window. assignment is before that require statement, and they are both after your other imports, and your ordering should remain as intended. The issue is caused by Babel hoisting imports such that they all get executed before any other code.

提交回复
热议问题