Skip to main content

Check if the current file is the entrypoint

还没翻译译自英文(bun.com)本页 3 段都还没译

Bun provides a handful of module-specific utilities on the import.meta object. Use import.meta.main to check if the current file is the entrypoint of the current process.

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

See import.meta.

翻訳 © 2026 fanyi.dev · 原文 © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)