Skip to main content
Bun 在 import.meta 对象上提供了一些模块特定的实用工具。使用 import.meta.main 可以检查当前文件是否为当前进程的入口点。
https://mintcdn.com/ikxin/RzFFGbzo0-4huILA/icons/typescript.svg?fit=max&auto=format&n=RzFFGbzo0-4huILA&q=85&s=a3dffd2241f05776d3bd25171d0c5a79index.ts
if (import.meta.main) {
  // 此文件是通过 `bun run` 直接执行的
} else {
  // 此文件被另一个文件导入
}

完整文档请参见 Docs > API > import.meta