vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.39k stars 6.07k forks source link

[Guidance] Setting `this` in IIFE's from older JS libs #1131

Closed arpowers closed 3 years ago

arpowers commented 3 years ago

As you may know, this is undefined in es6 modules: https://stackoverflow.com/questions/48670599/why-is-this-undefined-in-script-type-module

Because of this being undefined, there is a problem using older libs like this one: https://datamaps.github.io/ In these libs, they typically use IIFE's which assume this = window

Is there a way to patch this problem?

CHOYSEN commented 3 years ago

These libraries do not provide modular imports, so I think they should be used in the original way https://github.com/CHOYSEN/datamaps-example

arpowers commented 3 years ago

Thanks for the example, the problem with the implementation is just that the JS is loaded globally to the website. I suppose that's may be what we need to do to use this particular lib.

underfin commented 3 years ago

I only has two idea for this, that should work for you.

This always is not related of vite core, so i close it for clear issue, we also can disscus it.