示例工程 14-module-resolution-import-maps

14-module-resolution-import-maps/02-scopes/index.html

html · 0.7 KB

运行:14 · import map scopes

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>14 · import map scopes</title>
  <script type="importmap">
    {
      "imports": {
        "util": "./global/util.js"
      },
      "scopes": {
        "./vendor/": {
          "util": "./vendor/util.js"
        }
      }
    }
  </script>
</head>
<body>
  <p>打开 Console:同一个 util,在 vendor/ 下解析到不同实现。</p>
 
  <script type="module">
    import { name as appName } from 'util';
    import { nameFromVendor } from './vendor/lib.js';
    import { run } from './main.js';
 
    console.log('app 里的 util =>', appName);
    console.log('vendor/lib.js 里的 util =>', nameFromVendor);
    run();
  </script>
</body>
</html>