示例工程 16-mini-bundler

16-mini-bundler/03-bundle-inspector/README.md

markdown · 0.9 KB

运行:16 · 产物检查器

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

# 03 · 产物检查器
 
**演示**:从 `01-mini-bundler/dist/bundle.js` 的文本中提取模块 ID、数量、字节数,确认运行时函数存在;给出「平均每模块体积」。
**怎么看**:`node scripts/serve.mjs` 后打开 <http://localhost:8080/examples/16-mini-bundler/03-bundle-inspector/>,看页面与 Console。
**预期输出**:
 
```text
模块数:7
模块 ID:./src/main.js, ./src/app.js, ./src/logger.js, ./src/utils.js, ./src/config.js, ./src/cycle-a.js, ./src/cycle-b.js
产物大小:2186 字节(平均每模块 312 字节)
包含运行时:true
```
 
**注意**:示例用正则解析产物,只适用于迷你 bundler 的固定格式;真实工具应使用 AST 或构建统计(webpack `stats`、Rollup `bundle`)。模块 ID 的顺序是模块表插入顺序,不是求值顺序——求值顺序要看 `order`(`01` 的 CLI 输出)。需 `http://` 协议。