Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • This won't expose any global variables. It will hide them inside their own "namespace" (so to say), which will make them unusable. Commented Aug 11, 2020 at 16:36
  • 'old-style import-and-use libraries' generally expose themselves by adding a property to window object, so they become globally accessible. For example, when you import JQuery either by a separate <script /> tag or within another bundle file; $ object is added to window. If it is not the case for your foo.js library, there should be a problem how it is shipped. Commented Aug 12, 2020 at 8:35
  • 1
    Indeed. These libraries were defining functions without binding them to the window object. This works fine if you "include" the script from inside the HTML, but it doesn't work when using webpack's "import" statement (as everything get's wrapped inside an anonymous function). I modified the libraries in order to make them bind themselves to the window object and now everything works as expected. Commented Aug 12, 2020 at 9:44