summaryrefslogtreecommitdiff
path: root/docs/linking_to_external_code/import_maps.md
blob: 21b0477e4bb539b716aeda0d987ea1d23a610713 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
## Import maps

> This is an unstable feature. Learn more about
> [unstable features](../runtime/stability.md).

Deno supports [import maps](https://github.com/WICG/import-maps).

You can use import maps with the `--importmap=<FILE>` CLI flag.

Current limitations:

- single import map
- no fallback URLs
- Deno does not support `std:` namespace
- supports only `file:`, `http:` and `https:` schemes

Example:

**import_map.json**

```js
{
   "imports": {
      "fmt/": "https://deno.land/std@0.55.0/fmt/"
   }
}
```

**color.ts**

```ts
import { red } from "fmt/colors.ts";

console.log(red("hello world"));
```

Then:

```shell
$ deno run --importmap=import_map.json --unstable color.ts
```

To use staring directory for absolute imports:

```json
// import_map.json

{
  "imports": {
    "/": "./"
  }
}
```

```ts
// main.ts

import { MyUtil } from "/util.ts";
```

You may map a different directory: (eg. src)

```json
// import_map.json

{
  "imports": {
    "/": "./src"
  }
}
```