Open2
2023年秋、Bun v1を触る

Bunでモジュールバンドルを制作したい。
公式
Bun環境構築
ProductName: macOS
ProductVersion: 13.1
BuildVersion: 22C65
homebrewを利用する。
手順は、ドキュメント通りに実施する。
~ % brew -v
Homebrew 3.6.16
~ % brew tap oven-sh/bun
~ % brew install bun
~ % bun -v
1.0.3

{
"name": "hoge",
"module": "index.ts",
"type": "module",
"devDependencies": {
"bun-types": "latest"
},
"scripts": {
"build": "bun"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
Usage: bun build [flags] [...entrypoints]
Common Flags:
--outfile Write the output to a specific file (default: stdout)
--outdir Write the output to a directory (required for splitting)
--minify Enable all minification flags
--minify-whitespace Remove unneeded whitespace
--minify-syntax Transform code to use less syntax
--minify-identifiers Shorten variable names
--sourcemap Generate sourcemaps
("none", "inline", or "external")
--target The intended execution environment for the bundle.
("browser", "bun" or "node")
--splitting Enable code splitting (requires --outdir)
--watch Run bundler in watch mode
Examples:
Frontend web apps:
bun build ./src/index.ts --outfile=bundle.js
bun build --minify --splitting --outdir=out ./index.jsx ./lib/worker.ts
Bundle code to be run in Bun (reduces server startup time)
bun build --target=bun ./server.ts --outfile=server.js
Creating a standalone executable (see https://bun.sh/docs/bundler/executables)
bun build --compile ./cli.ts --outfile=my-app
A full list of flags is available at https://bun.sh/docs/bundler