import-maps icon indicating copy to clipboard operation
import-maps copied to clipboard

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

Open trusktr opened this issue 3 years ago • 1 comments

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 avatar Jan 01 '23 19:01 trusktr

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.

trusktr avatar Jan 01 '23 20:01 trusktr