示例工程 12-umd-systemjs
12-umd-systemjs/01-umd-wrapper/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>12 · UMD 包装</title>
</head>
<body>
<p>打开 Console 查看同一份 UMD 在三种环境下的结果。</p>
<script src="./umd-lib.js"></script>
<script type="module">
import { run } from './main.js';
// 全局分支:直接作为脚本加载后,UmdLib 挂在 window 上
console.log('script 标签加载 =>', window.UmdLib.version, window.UmdLib.add(2, 3));
run().then((rows) => console.log('三种环境一致 =>', rows.length === 3));
</script>
</body>
</html>