Bun

指南實用程式

使用 Bun 獲取當前入口點的絕對路徑

Bun.main 屬性包含當前入口點的絕對路徑。

foo.ts
index.ts
foo.ts
console.log(Bun.main);
index.ts
import "./foo.ts";

列印的路徑對應於使用 bun run 執行的檔案。

bun run index.ts
/path/to/index.ts
bun run foo.ts
/path/to/foo.ts

有關更多有用的工具,請參閱 文件 > API > 工具