Import map
Description
Import maps are a WICG proposal, already used by the Deno runtime. In GJS it's hard to import arbitrary npm modules, therefore we often need to use bundlers and other external programs.
Import maps could bypass the problem of using bundlers.
Example: I can download the required js dependencies manually, using tools as download-esm.
Let's say I want to use solid-js
.
download-esm solid-js ./downloaded-modules
Then in the import map I'm going to write
{
imports: {
"solid-js": "./downloaded-modules/solid-js-v1234928734987239478-asdf.js"
}
}
and then in my index.js
file I can use solid-js
as a normal module
import solid from "solid-js"
// instead of `import x from ./downloaded-modules/solid-js-v1234928734987239478-asdf.js`
// which would make the file unportable
Now I can run index.js directly, with gjs
, without any bundler or any external program.
gjs --import-map import_map.json -m index.js
Ideally an external program could manage the import-map, download the required dependencies and generate a lock file. All of this, while not requiring any collaboration from gjs, except reading the import map.
Prior Art
https://deno.com/manual@v1.33.4/basics/import_maps#import-maps