2020-05-06 18:21:13 -04:00
|
|
|
## Import maps
|
|
|
|
|
|
|
|
> This is an unstable feature. Learn more about
|
2020-05-09 09:15:26 -04:00
|
|
|
> [unstable features](../runtime/stability.md).
|
2020-05-06 18:21:13 -04:00
|
|
|
|
|
|
|
Deno supports [import maps](https://github.com/WICG/import-maps).
|
|
|
|
|
2020-05-18 15:53:25 -04:00
|
|
|
You can use import maps with the `--importmap=<FILE>` CLI flag.
|
2020-05-06 18:21:13 -04:00
|
|
|
|
|
|
|
Current limitations:
|
|
|
|
|
|
|
|
- single import map
|
|
|
|
- no fallback URLs
|
|
|
|
- Deno does not support `std:` namespace
|
|
|
|
- supports only `file:`, `http:` and `https:` schemes
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2020-06-10 13:43:44 -04:00
|
|
|
**import_map.json**
|
2020-05-06 18:21:13 -04:00
|
|
|
|
2020-06-10 13:43:44 -04:00
|
|
|
```js
|
2020-05-06 18:21:13 -04:00
|
|
|
{
|
|
|
|
"imports": {
|
2020-06-10 13:43:44 -04:00
|
|
|
"fmt/": "https://deno.land/std@0.55.0/fmt/"
|
2020-05-06 18:21:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-06-10 13:43:44 -04:00
|
|
|
**color.ts**
|
2020-05-06 18:21:13 -04:00
|
|
|
|
2020-06-10 13:43:44 -04:00
|
|
|
```ts
|
|
|
|
import { red } from "fmt/colors.ts";
|
2020-05-06 18:21:13 -04:00
|
|
|
|
2020-06-10 13:43:44 -04:00
|
|
|
console.log(red("hello world"));
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|
|
|
|
|
2020-06-10 13:43:44 -04:00
|
|
|
Then:
|
|
|
|
|
2020-05-06 18:21:13 -04:00
|
|
|
```shell
|
2020-06-10 13:43:44 -04:00
|
|
|
$ deno run --importmap=import-map.json --unstable color.ts
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|