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

Import maps

Open mikabytes opened this issue 4 years ago • 1 comments

Brace for craziness.

Chrome released official support for import maps on March 1. There's a polyfill enabling this in all browsers which have support for ES modules. It would be awesome if importjs could understand these maps, download the specifications, and set up my imports for me.

Example:

<script type="importmap">
{
  "imports": {
    "moment": "/node_modules/moment/src/moment.js",
    "vue": "https://www.unpkg.com/vue/dist/vue.runtime.esm.js"
  }
}
</script>
<script type="module">
import moment from "moment";

// do something with moment here
</script>
<scrypt type="module" src="./my-main-file"></script>

Once an import map is defined (inline or in separate file), then it affects all named imports that happen after it.

https://github.com/WICG/import-maps https://caniuse.com/import-maps

This is a tricky thing to implement to 100%. But I'm thinking I might give it a shot to at least get some partial support. Maybe have ImportJS look at one specific file for importmaps at startup and then ignore the rest.

Perhaps urls could be downloaded to a node_modules-like folder and let importjs do its things as usual from that point forwards.

mikabytes avatar Apr 14 '21 20:04 mikabytes

Oh, and just to be clear: this will be for web projects only. There is no package.json file, no dependency management, etc.

mikabytes avatar Apr 14 '21 20:04 mikabytes

It's been two years and I haven't gotten around to implementing this. There are a few reasons why;

  • I was hoping external import maps would be implemented as defined in the spec, but still to this date major browsers haven't done it (Chrome for one has a long outstanding ticket). Managing a single file dedicated to import maps would be easier to move into ImportJS than a mix of HTML, CSS, etc.
  • To figure out what dependencies are there, ImportJS would have to download the files from the web. We probably don't want it to do that in realtime, but rather as a one-off configuration event. If so, writing a tool that does the same and places the result in the .importjs.js file would be just as easy.

I just get the vibe that this doesn't belong in ImportJS. At least not yet. So I'm closing this for now and might reopen in a couple of years :smile:

mikabytes avatar Jan 25 '24 11:01 mikabytes