Galooshi / import-js

A tool to simplify importing JS modules
MIT License
526 stars 70 forks source link

Import maps #564

Closed mikabytes closed 7 months ago

mikabytes commented 3 years ago

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 commented 3 years ago

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

mikabytes commented 7 months ago

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

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: