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

Import maps #564

Closed
mikabytes opened this issue Apr 14, 2021 · 2 comments
Closed

Import maps #564

mikabytes opened this issue Apr 14, 2021 · 2 comments

Comments

@mikabytes
Copy link
Collaborator

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
Copy link
Collaborator Author

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

@mikabytes
Copy link
Collaborator Author

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 😄

This was referenced Feb 4, 2024
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