引入maps

这是一个不稳定的特性。详情请参考 稳定性.

Deno支持引入maps.

可以使用 --importmap=<FILE> 这个脚手架标识来引入map。

当前的局限性:

  • 单个的map引入
  • 没有降级处理的URL
  • Deno不支持std:命名空间
  • 只支持file:, http:https:模式

举个栗子🌰:

  1. // import_map.json
  2. {
  3. "imports": {
  4. "http/": "https://deno.land/std/http/"
  5. }
  6. }
  1. // hello_server.ts
  2. import { serve } from "http/server.ts";
  3. const body = new TextEncoder().encode("Hello World\n");
  4. for await (const req of serve(":8000")) {
  5. req.respond({ body });
  6. }
  1. $ deno run --importmap=import_map.json --unstable hello_server.ts