Skip to content

Import Maps

Since Reejs supports URL Imports, we decided to support import maps for our project. It is necessary to use import maps to support the browser scope too. Any Reejs code is isomorphic, that means if it runs on one runtime, it will run on the other too (with some exceptions like native modules).

Any project generated by Reejs comes shipped with a import_map.json file at the root of the project.

Our version of import_map.json comes with two sections: imports and browserImports. While browserImports is not officially supported by the spec, Deno doesn't complain about it and so we decided to use it to support the browser scope.

js
{
  "imports": {
    // ...
  },
  "browserImports":{
    // ...
  }
}

By default if imports doesn't have a map for a package, Reejs will look for it the same package in browserImports and even if still not availabe, it won't use anything.

Overriding Imports

From Deno's Documentation

The other situation where import maps can be very useful is to override imports in specific modules.

Let’s say you want to override the deno_std import from 0.177.0 to the latest in all of your imported modules, but for the https://deno.land/x/example/ module you want to use files in a local patched directory. You can do this by using a scope in the import map that looks something like this:

js
{
  "imports": {
    "https://deno.land/std@0.177.0/": "https://deno.land/std@0.192.0/"
  },
  "scopes": {
    "https://deno.land/x/example/": {
      "https://deno.land/std@0.177.0/": "./patched/"
    }
  }
}

Released under the MIT License.