Importmap

An example of Three.js

index.html
<script type="importmap">
    {
      "imports": {
              "three": "/node_modules/three/build/three.module.js"
      }
    }
  </script>
  <script type="module" src="./js/script.js"></script>
script.js
import * as THREE from 'three'

By providing the attribute type="importmap" on a script tag, you can define this map and then define a series of bare import names and a relative or absolute URL. Remember that if you are specifying a relative URL such as the example below, the location of that file should be relative to the file where the import-maps is defined, which is index.html in this instance:

After defining this map, you can directly import three anywhere in your code.

Last updated