Open trusktr opened 10 months ago
Maybe the spec needs an update to allow aliasing withing the importmap itself? It seems like what I did should work, just the same was as the importmap modifies import specifiers in JS source code.
But if it isn't possible to allow this for some reason, then maybe a special syntax can be used? F.e.
<script type="importmap">
{
"imports": {
":mods": "../../../node_modules/",
"@amazon-sumerian-hosts/core": ":mods/@amazon-sumerian-hosts/core/src/core/index.js",
"@amazon-sumerian-hosts/three": ":mods/@amazon-sumerian-hosts/three/src/three.js/index.js"
}
}
</script>
in this example using a :
symbol.
Another reason this need pops up is writing HTML files in folders at different depths in the file system, where when you make a new file copied from another, you then need to update all the relative paths in the import map. I was trying to reduce it to a single modification instead of one per entry.
A current way to solve this is to make a <script modules="../../../node_modules">
or similar script that document.write
s the importmap dynamically.
For example, this
gives me these two warnings,
followed by this error:
I often find that I want to use a particular import map (copy/pasted from somewhere) and that sometimes the
node_modules
location is the only thing that changes. So I figured it would be easy to define wherenode_modules
is a single time (to keep things more DRY) then re-use that location further on in the import map. In other words, when I copy/paste an import map to get something working in one project or other, I was trying to avoid having to modify many occurrences of../../../node_modules/
, and instead modify only one occurrence.