WICG/import-maps

ability to specify a default extension for extensionless URLs

trusktr opened this issue · 3 comments

It can be annoying when using vanilla modules, and some library ships their code with extensionless specifiers.

Some ways to solve the issue:

  • ask them to update their code (could take time)
  • fork the code (could be a hassle)
  • add a ServiceWorker to an app, and have it add extensions to intercepted URLs. But it's a bit overkill.

Perhaps it would be nice if there were a way to solve this in importmaps. This would be the easiest for end devs.

Here's a random idea to get the idea across, without too much thought:

<script type="importmap">{
  "imports": {
    ... same as before ...,
  },
  "extensions: {
    "/some/path/": ".js"
  }
}</script>

perhaps similar to how scopes are defined.

The idea in

is more generic with its globbing syntax and would allow more possibilities, but is thus also more complicated. The idea in this issue specifically focuses on extensions, and a way to specify them without a globbing syntax, similar to scopes.

What effect do you think extensions have?

@michaelficarra nothing except changing the URL of the file being fetched, just like all else in an importmap. It has no effect on mime types, importmaps are all about mapping URLs. (right?)