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
Eric Zingeler d2b32a65a7
docs(import_maps): Add trailing slash to ./src example (#8524)
Update docs to reflect behavior. If trailing slash is not provided, `deno run` will throw error `Package address targets must end with "/"`.
2020-11-27 13:33:43 -05:00

1,003 B

Import maps

This is an unstable feature. Learn more about unstable features.

Deno supports import maps.

You can use import maps with the --import-map=<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

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

color.ts

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

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

Then:

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

To use starting directory for absolute imports:

// import_map.json

{
  "imports": {
    "/": "./"
  }
}
// main.ts

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

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

// import_map.json

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