美文网首页
4.5 导入 maps

4.5 导入 maps

作者: 9e8aeff1c70c | 来源:发表于2021-05-19 10:31 被阅读0次

Deno支持 import maps.

您可以使用带有--import-map=<file>CLI标志的导入map。

示例:

import_map.json

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

color.ts

import { red } from "fmt/colors.ts";
console.log(red("hello world"));

然后:

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

要使用项目根目录进行绝对导入,请执行以下操作:

import_map.json

{
  "imports": {
    "/": "./",
    "./": "./"
  }
}

main.ts

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

这会导致相对于导入映射的URL或文件路径解析以/开头的导入说明符。

相关文章

网友评论

      本文标题:4.5 导入 maps

      本文链接:https://www.haomeiwen.com/subject/ieyerltx.html