1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 09:10:40 -05:00
denoland-deno/docs/linking_to_external_code/import_maps.md

54 lines
743 B
Markdown
Raw Normal View History

2020-05-06 18:21:13 -04:00
## Import maps
Deno supports [import maps](https://github.com/WICG/import-maps).
You can use import maps with the `--import-map=<FILE>` CLI flag.
2020-05-06 18:21:13 -04:00
Example:
**import_map.json**
2020-05-06 18:21:13 -04:00
```js
2020-05-06 18:21:13 -04:00
{
"imports": {
"fmt/": "https://deno.land/std@$STD_VERSION/fmt/"
2020-05-06 18:21:13 -04:00
}
}
```
**color.ts**
2020-05-06 18:21:13 -04:00
```ts
import { red } from "fmt/colors.ts";
2020-05-06 18:21:13 -04:00
console.log(red("hello world"));
2020-05-06 18:21:13 -04:00
```
Then:
2020-05-06 18:21:13 -04:00
```shell
$ deno run --import-map=import_map.json color.ts
2020-05-06 18:21:13 -04:00
```
To use your project root for absolute imports:
**import_map.json**
```jsonc
{
"imports": {
"/": "./",
"./": "./"
}
}
```
**main.ts**
```ts
import { MyUtil } from "/util.ts";
```
This causes import specifiers starting with `/` to be resolved relative to the
import map's URL or file path.