summaryrefslogtreecommitdiff
path: root/docs/linking_to_external_code/import_maps.md
blob: c00aa0290f357d446d5c10c90c8246fbd92ee770 (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
## Import maps

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

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

Example:

**import_map.json**

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

**color.ts**

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

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

Then:

```shell
$ deno run --import-map=import_map.json color.ts
```

To use starting directory for absolute imports:

**import_map.json**

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

**main.ts**

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

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

**import_map.json**

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