Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global variables (f.e. map "jquery" specifier to globalThis.jquery variable) #288

Open
trusktr opened this issue Jan 1, 2023 · 1 comment

Comments

@trusktr
Copy link

trusktr commented Jan 1, 2023

I know this goes against the concept of modules, but it feels like something necessary to help people migrate.

<script type="importmap">
{
  "imports": {
    "jquery": "env:$",
    "three": "env:THREE",
  }
}
</script>

where env:$ causes import * as jQuery from "jquery" to import from a global $ variable, and similar with three.js.

There would be no static analysis in this case. Maybe it would have a runtime check, so that import {blah} from 'jquery' would fail if "blah" in $ is false.


why

I struggle with these sorts of things often. In a lot of cases I don't want to go and spend (possibly valuable and costly) time refactoring existing apps, but I want an easy way to move forward if I can.

@trusktr
Copy link
Author

trusktr commented Jan 1, 2023

This would be sweet, because with little restructure of an app, new features could start to import things and get modern type support and intellisense simply with npm i @types/jquery without having to configure additional global types.

From a purist module perspective, I can understand we don't want modules to grab things from global. But from a practical standpoint, it seems like it would so incredibly useful, especially for the many many apps that already exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant