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

ability to specify a default extension for extensionless URLs

Open trusktr opened this issue 2 years ago • 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.

trusktr avatar Aug 28 '23 05:08 trusktr

The idea in

  • https://github.com/WICG/import-maps/issues/7

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.

trusktr avatar Aug 28 '23 05:08 trusktr

What effect do you think extensions have?

michaelficarra avatar Aug 28 '23 20:08 michaelficarra

@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?)

trusktr avatar Oct 01 '23 18:10 trusktr