Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What's the main benefit of import-maps?

Reading the article it seems to me you must code the import map which basically defines aliases for your scripts. Then you must use the aliases to actually get access to the scripts you want to use.

You must specify the absolute URL of the imports whether you use import-maps or not so what's the benefit? Does this reduce the amount of code?

I'm sure there is a benefit I just don't see it on first reading of this article.



Basically package.json but without package.json. IE no bundle JS is back.

There are still some issues, specifically with things like React, where it's kind of hard to guarantee if you use React, you'll get the same version if you use it in "react-relay" etc.

Deno has been very informative on this. They're adding package.json support to the runtime as a polyfill, but I'm hopeful they can swing back to import maps fully over time.


It also allows easy loading of micro-frontends, if that's the architecture you're shooting for.

https://single-spa.js.org/docs/recommended-setup/


I see. So the benefit is that you externalize your imports into a file separate from you code. Right? I can see the benefit of that. It is like meta-data about your module, kept separate from it. And several modules can use the same imports-map, right? That means amount of code needed gets less.

Thanks for the explanation. I assume I got it right, did I?

Or now I wonder, must the imports-map be defined in the same module where it is used?


No, you might have one "global" importmap in your HTML file and that applies to the entire graph of modules you load after that, which also means that you can "chain" importmaps and can also do things like pin the versions of dependencies of dependencies in that top level importmap. That sort of thing will need package-management-like tooling and dependency "packages" built for it, but that gets back to the idea that importmaps in theory are a lighter weight replacement for package.json/package-lock.json files.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: