Bun

指南實用程式

使用 Bun 檢查當前檔案是否是入口點

Bun 在 import.meta 物件上提供了一些模組特定的實用程式。使用 import.meta.main 來檢查當前檔案是否是當前程序的入口點。

index.ts
if (import.meta.main) {
  // this file is directly executed with `bun run`
} else {
  // this file is being imported by another file
}

有關完整的文件,請參閱 文件 > API > import.meta