bun-types 1.3.2-canary.20251105T140650 → 1.3.2-canary.20251106T140813

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/docs/README.md +28 -0
  2. package/package.json +1 -1
  3. package/docs/api/binary-data.md +0 -1038
  4. package/docs/api/cc.md +0 -197
  5. package/docs/api/color.md +0 -262
  6. package/docs/api/console.md +0 -57
  7. package/docs/api/cookie.md +0 -449
  8. package/docs/api/dns.md +0 -110
  9. package/docs/api/fetch.md +0 -463
  10. package/docs/api/ffi.md +0 -557
  11. package/docs/api/file-io.md +0 -366
  12. package/docs/api/file-system-router.md +0 -112
  13. package/docs/api/file.md +0 -19
  14. package/docs/api/glob.md +0 -178
  15. package/docs/api/globals.md +0 -387
  16. package/docs/api/hashing.md +0 -319
  17. package/docs/api/html-rewriter.md +0 -334
  18. package/docs/api/http.md +0 -1408
  19. package/docs/api/import-meta.md +0 -69
  20. package/docs/api/node-api.md +0 -14
  21. package/docs/api/redis.md +0 -597
  22. package/docs/api/s3.md +0 -850
  23. package/docs/api/secrets.md +0 -319
  24. package/docs/api/semver.md +0 -52
  25. package/docs/api/spawn.md +0 -582
  26. package/docs/api/sql.md +0 -1374
  27. package/docs/api/sqlite.md +0 -694
  28. package/docs/api/streams.md +0 -230
  29. package/docs/api/tcp.md +0 -221
  30. package/docs/api/transpiler.md +0 -276
  31. package/docs/api/udp.md +0 -123
  32. package/docs/api/utils.md +0 -891
  33. package/docs/api/websockets.md +0 -573
  34. package/docs/api/workers.md +0 -322
  35. package/docs/api/yaml.md +0 -668
  36. package/docs/benchmarks.md +0 -120
  37. package/docs/bun-flavored-toml.md +0 -42
  38. package/docs/bundler/css.md +0 -1028
  39. package/docs/bundler/css_modules.md +0 -145
  40. package/docs/bundler/executables.md +0 -626
  41. package/docs/bundler/fullstack.md +0 -418
  42. package/docs/bundler/hmr.md +0 -234
  43. package/docs/bundler/html.md +0 -349
  44. package/docs/bundler/index.md +0 -1735
  45. package/docs/bundler/intro.md +0 -75
  46. package/docs/bundler/loaders.md +0 -410
  47. package/docs/bundler/macros.md +0 -329
  48. package/docs/bundler/plugins.md +0 -449
  49. package/docs/bundler/vs-esbuild.md +0 -1127
  50. package/docs/cli/add.md +0 -173
  51. package/docs/cli/bun-completions.md +0 -3
  52. package/docs/cli/bun-create.md +0 -338
  53. package/docs/cli/bun-install.md +0 -349
  54. package/docs/cli/bun-upgrade.md +0 -39
  55. package/docs/cli/bunx.md +0 -89
  56. package/docs/cli/filter.md +0 -90
  57. package/docs/cli/info.md +0 -65
  58. package/docs/cli/init.md +0 -85
  59. package/docs/cli/install.md +0 -344
  60. package/docs/cli/link.md +0 -40
  61. package/docs/cli/outdated.md +0 -90
  62. package/docs/cli/patch-commit.md +0 -11
  63. package/docs/cli/pm.md +0 -285
  64. package/docs/cli/publish.md +0 -120
  65. package/docs/cli/remove.md +0 -7
  66. package/docs/cli/run.md +0 -261
  67. package/docs/cli/test.md +0 -397
  68. package/docs/cli/unlink.md +0 -9
  69. package/docs/cli/update.md +0 -129
  70. package/docs/cli/why.md +0 -67
  71. package/docs/contributing/upgrading-webkit.md +0 -57
  72. package/docs/ecosystem/elysia.md +0 -24
  73. package/docs/ecosystem/express.md +0 -37
  74. package/docs/ecosystem/hono.md +0 -18
  75. package/docs/ecosystem/react.md +0 -65
  76. package/docs/ecosystem/stric.md +0 -38
  77. package/docs/guides/binary/arraybuffer-to-array.md +0 -27
  78. package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
  79. package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
  80. package/docs/guides/binary/arraybuffer-to-string.md +0 -15
  81. package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
  82. package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
  83. package/docs/guides/binary/blob-to-dataview.md +0 -14
  84. package/docs/guides/binary/blob-to-stream.md +0 -14
  85. package/docs/guides/binary/blob-to-string.md +0 -15
  86. package/docs/guides/binary/blob-to-typedarray.md +0 -14
  87. package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
  88. package/docs/guides/binary/buffer-to-blob.md +0 -14
  89. package/docs/guides/binary/buffer-to-readablestream.md +0 -41
  90. package/docs/guides/binary/buffer-to-string.md +0 -25
  91. package/docs/guides/binary/buffer-to-typedarray.md +0 -14
  92. package/docs/guides/binary/dataview-to-string.md +0 -15
  93. package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
  94. package/docs/guides/binary/typedarray-to-blob.md +0 -16
  95. package/docs/guides/binary/typedarray-to-buffer.md +0 -14
  96. package/docs/guides/binary/typedarray-to-dataview.md +0 -14
  97. package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
  98. package/docs/guides/binary/typedarray-to-string.md +0 -16
  99. package/docs/guides/deployment/railway.md +0 -157
  100. package/docs/guides/ecosystem/astro.md +0 -72
  101. package/docs/guides/ecosystem/discordjs.md +0 -77
  102. package/docs/guides/ecosystem/docker.md +0 -140
  103. package/docs/guides/ecosystem/drizzle.md +0 -185
  104. package/docs/guides/ecosystem/edgedb.md +0 -228
  105. package/docs/guides/ecosystem/elysia.md +0 -31
  106. package/docs/guides/ecosystem/express.md +0 -40
  107. package/docs/guides/ecosystem/hono.md +0 -39
  108. package/docs/guides/ecosystem/mongoose.md +0 -87
  109. package/docs/guides/ecosystem/neon-drizzle.md +0 -220
  110. package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
  111. package/docs/guides/ecosystem/nextjs.md +0 -49
  112. package/docs/guides/ecosystem/nuxt.md +0 -56
  113. package/docs/guides/ecosystem/pm2.md +0 -57
  114. package/docs/guides/ecosystem/prisma.md +0 -141
  115. package/docs/guides/ecosystem/qwik.md +0 -107
  116. package/docs/guides/ecosystem/react.md +0 -50
  117. package/docs/guides/ecosystem/remix.md +0 -78
  118. package/docs/guides/ecosystem/render.md +0 -79
  119. package/docs/guides/ecosystem/sentry.md +0 -52
  120. package/docs/guides/ecosystem/solidstart.md +0 -58
  121. package/docs/guides/ecosystem/ssr-react.md +0 -51
  122. package/docs/guides/ecosystem/stric.md +0 -55
  123. package/docs/guides/ecosystem/sveltekit.md +0 -125
  124. package/docs/guides/ecosystem/systemd.md +0 -113
  125. package/docs/guides/ecosystem/vite.md +0 -71
  126. package/docs/guides/html-rewriter/extract-links.md +0 -68
  127. package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
  128. package/docs/guides/http/cluster.md +0 -66
  129. package/docs/guides/http/fetch-unix.md +0 -33
  130. package/docs/guides/http/fetch.md +0 -24
  131. package/docs/guides/http/file-uploads.md +0 -94
  132. package/docs/guides/http/hot.md +0 -26
  133. package/docs/guides/http/proxy.md +0 -24
  134. package/docs/guides/http/server.md +0 -46
  135. package/docs/guides/http/simple.md +0 -18
  136. package/docs/guides/http/stream-file.md +0 -48
  137. package/docs/guides/http/stream-iterator.md +0 -47
  138. package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
  139. package/docs/guides/http/tls.md +0 -30
  140. package/docs/guides/install/add-dev.md +0 -26
  141. package/docs/guides/install/add-git.md +0 -36
  142. package/docs/guides/install/add-optional.md +0 -25
  143. package/docs/guides/install/add-peer.md +0 -43
  144. package/docs/guides/install/add-tarball.md +0 -33
  145. package/docs/guides/install/add.md +0 -42
  146. package/docs/guides/install/azure-artifacts.md +0 -73
  147. package/docs/guides/install/cicd.md +0 -41
  148. package/docs/guides/install/custom-registry.md +0 -30
  149. package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
  150. package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
  151. package/docs/guides/install/jfrog-artifactory.md +0 -28
  152. package/docs/guides/install/npm-alias.md +0 -23
  153. package/docs/guides/install/registry-scope.md +0 -38
  154. package/docs/guides/install/trusted.md +0 -46
  155. package/docs/guides/install/workspaces.md +0 -70
  156. package/docs/guides/install/yarnlock.md +0 -44
  157. package/docs/guides/process/argv.md +0 -58
  158. package/docs/guides/process/ctrl-c.md +0 -16
  159. package/docs/guides/process/ipc.md +0 -66
  160. package/docs/guides/process/nanoseconds.md +0 -13
  161. package/docs/guides/process/os-signals.md +0 -39
  162. package/docs/guides/process/spawn-stderr.md +0 -31
  163. package/docs/guides/process/spawn-stdout.md +0 -26
  164. package/docs/guides/process/spawn.md +0 -41
  165. package/docs/guides/process/stdin.md +0 -54
  166. package/docs/guides/read-file/arraybuffer.md +0 -28
  167. package/docs/guides/read-file/buffer.md +0 -19
  168. package/docs/guides/read-file/exists.md +0 -16
  169. package/docs/guides/read-file/json.md +0 -17
  170. package/docs/guides/read-file/mime.md +0 -20
  171. package/docs/guides/read-file/stream.md +0 -26
  172. package/docs/guides/read-file/string.md +0 -22
  173. package/docs/guides/read-file/uint8array.md +0 -21
  174. package/docs/guides/read-file/watch.md +0 -68
  175. package/docs/guides/runtime/build-time-constants.md +0 -293
  176. package/docs/guides/runtime/cicd.md +0 -43
  177. package/docs/guides/runtime/codesign-macos-executable.md +0 -56
  178. package/docs/guides/runtime/define-constant.md +0 -145
  179. package/docs/guides/runtime/delete-directory.md +0 -37
  180. package/docs/guides/runtime/delete-file.md +0 -19
  181. package/docs/guides/runtime/heap-snapshot.md +0 -26
  182. package/docs/guides/runtime/import-html.md +0 -15
  183. package/docs/guides/runtime/import-json.md +0 -44
  184. package/docs/guides/runtime/import-toml.md +0 -30
  185. package/docs/guides/runtime/import-yaml.md +0 -102
  186. package/docs/guides/runtime/read-env.md +0 -32
  187. package/docs/guides/runtime/set-env.md +0 -47
  188. package/docs/guides/runtime/shell.md +0 -40
  189. package/docs/guides/runtime/timezone.md +0 -35
  190. package/docs/guides/runtime/tsconfig-paths.md +0 -29
  191. package/docs/guides/runtime/typescript.md +0 -49
  192. package/docs/guides/runtime/vscode-debugger.md +0 -47
  193. package/docs/guides/runtime/web-debugger.md +0 -82
  194. package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
  195. package/docs/guides/streams/node-readable-to-blob.md +0 -11
  196. package/docs/guides/streams/node-readable-to-json.md +0 -12
  197. package/docs/guides/streams/node-readable-to-string.md +0 -12
  198. package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
  199. package/docs/guides/streams/to-array.md +0 -14
  200. package/docs/guides/streams/to-arraybuffer.md +0 -14
  201. package/docs/guides/streams/to-blob.md +0 -14
  202. package/docs/guides/streams/to-buffer.md +0 -15
  203. package/docs/guides/streams/to-json.md +0 -14
  204. package/docs/guides/streams/to-string.md +0 -14
  205. package/docs/guides/streams/to-typedarray.md +0 -22
  206. package/docs/guides/test/bail.md +0 -22
  207. package/docs/guides/test/coverage-threshold.md +0 -60
  208. package/docs/guides/test/coverage.md +0 -44
  209. package/docs/guides/test/happy-dom.md +0 -68
  210. package/docs/guides/test/migrate-from-jest.md +0 -143
  211. package/docs/guides/test/mock-clock.md +0 -48
  212. package/docs/guides/test/mock-functions.md +0 -68
  213. package/docs/guides/test/rerun-each.md +0 -14
  214. package/docs/guides/test/run-tests.md +0 -111
  215. package/docs/guides/test/skip-tests.md +0 -39
  216. package/docs/guides/test/snapshot.md +0 -95
  217. package/docs/guides/test/spy-on.md +0 -46
  218. package/docs/guides/test/svelte-test.md +0 -120
  219. package/docs/guides/test/testing-library.md +0 -92
  220. package/docs/guides/test/timeout.md +0 -15
  221. package/docs/guides/test/todo-tests.md +0 -67
  222. package/docs/guides/test/update-snapshots.md +0 -46
  223. package/docs/guides/test/watch-mode.md +0 -19
  224. package/docs/guides/util/base64.md +0 -15
  225. package/docs/guides/util/deep-equals.md +0 -39
  226. package/docs/guides/util/deflate.md +0 -18
  227. package/docs/guides/util/detect-bun.md +0 -23
  228. package/docs/guides/util/entrypoint.md +0 -17
  229. package/docs/guides/util/escape-html.md +0 -22
  230. package/docs/guides/util/file-url-to-path.md +0 -14
  231. package/docs/guides/util/gzip.md +0 -18
  232. package/docs/guides/util/hash-a-password.md +0 -54
  233. package/docs/guides/util/import-meta-dir.md +0 -13
  234. package/docs/guides/util/import-meta-file.md +0 -13
  235. package/docs/guides/util/import-meta-path.md +0 -13
  236. package/docs/guides/util/javascript-uuid.md +0 -23
  237. package/docs/guides/util/main.md +0 -32
  238. package/docs/guides/util/path-to-file-url.md +0 -14
  239. package/docs/guides/util/sleep.md +0 -22
  240. package/docs/guides/util/version.md +0 -21
  241. package/docs/guides/util/which-path-to-executable-bin.md +0 -15
  242. package/docs/guides/websocket/compression.md +0 -31
  243. package/docs/guides/websocket/context.md +0 -77
  244. package/docs/guides/websocket/pubsub.md +0 -41
  245. package/docs/guides/websocket/simple.md +0 -33
  246. package/docs/guides/write-file/append.md +0 -52
  247. package/docs/guides/write-file/basic.md +0 -44
  248. package/docs/guides/write-file/blob.md +0 -28
  249. package/docs/guides/write-file/cat.md +0 -17
  250. package/docs/guides/write-file/file-cp.md +0 -16
  251. package/docs/guides/write-file/filesink.md +0 -52
  252. package/docs/guides/write-file/response.md +0 -17
  253. package/docs/guides/write-file/stdout.md +0 -21
  254. package/docs/guides/write-file/stream.md +0 -17
  255. package/docs/guides/write-file/unlink.md +0 -16
  256. package/docs/index.md +0 -77
  257. package/docs/install/audit.md +0 -57
  258. package/docs/install/cache.md +0 -59
  259. package/docs/install/catalogs.md +0 -298
  260. package/docs/install/index.md +0 -248
  261. package/docs/install/isolated.md +0 -197
  262. package/docs/install/lifecycle.md +0 -46
  263. package/docs/install/lockfile.md +0 -58
  264. package/docs/install/npmrc.md +0 -105
  265. package/docs/install/overrides.md +0 -73
  266. package/docs/install/patch.md +0 -59
  267. package/docs/install/registries.md +0 -30
  268. package/docs/install/security-scanner-api.md +0 -81
  269. package/docs/install/workspaces.md +0 -114
  270. package/docs/installation.md +0 -327
  271. package/docs/project/asan.md +0 -124
  272. package/docs/project/benchmarking.md +0 -203
  273. package/docs/project/bindgen.md +0 -225
  274. package/docs/project/building-windows.md +0 -162
  275. package/docs/project/contributing.md +0 -347
  276. package/docs/project/internals/build-process-for-ci.md +0 -75
  277. package/docs/project/licensing.md +0 -73
  278. package/docs/project/roadmap.md +0 -87
  279. package/docs/quickstart.md +0 -157
  280. package/docs/runtime/autoimport.md +0 -94
  281. package/docs/runtime/bun-apis.md +0 -207
  282. package/docs/runtime/bunfig.md +0 -772
  283. package/docs/runtime/debugger.md +0 -325
  284. package/docs/runtime/env.md +0 -253
  285. package/docs/runtime/hot.md +0 -145
  286. package/docs/runtime/index.md +0 -312
  287. package/docs/runtime/jsx.md +0 -385
  288. package/docs/runtime/loaders.md +0 -130
  289. package/docs/runtime/modules.md +0 -320
  290. package/docs/runtime/nodejs-apis.md +0 -463
  291. package/docs/runtime/plugins.md +0 -561
  292. package/docs/runtime/shell.md +0 -605
  293. package/docs/runtime/typescript.md +0 -139
  294. package/docs/runtime/web-apis.md +0 -128
  295. package/docs/test/configuration.md +0 -154
  296. package/docs/test/coverage.md +0 -142
  297. package/docs/test/discovery.md +0 -85
  298. package/docs/test/dom.md +0 -75
  299. package/docs/test/examples/concurrent-test-glob.md +0 -132
  300. package/docs/test/hot.md +0 -15
  301. package/docs/test/lifecycle.md +0 -81
  302. package/docs/test/mocks.md +0 -313
  303. package/docs/test/reporters.md +0 -117
  304. package/docs/test/runtime-behavior.md +0 -95
  305. package/docs/test/snapshots.md +0 -68
  306. package/docs/test/time.md +0 -126
  307. package/docs/test/writing.md +0 -825
  308. package/docs/typescript.md +0 -53
@@ -1,626 +0,0 @@
1
- Bun's bundler implements a `--compile` flag for generating a standalone binary from a TypeScript or JavaScript file.
2
-
3
- {% codetabs %}
4
-
5
- ```bash
6
- $ bun build ./cli.ts --compile --outfile mycli
7
- ```
8
-
9
- ```ts#cli.ts
10
- console.log("Hello world!");
11
- ```
12
-
13
- {% /codetabs %}
14
-
15
- This bundles `cli.ts` into an executable that can be executed directly:
16
-
17
- ```
18
- $ ./mycli
19
- Hello world!
20
- ```
21
-
22
- All imported files and packages are bundled into the executable, along with a copy of the Bun runtime. All built-in Bun and Node.js APIs are supported.
23
-
24
- ## Cross-compile to other platforms
25
-
26
- The `--target` flag lets you compile your standalone executable for a different operating system, architecture, or version of Bun than the machine you're running `bun build` on.
27
-
28
- To build for Linux x64 (most servers):
29
-
30
- ```sh
31
- bun build --compile --target=bun-linux-x64 ./index.ts --outfile myapp
32
-
33
- # To support CPUs from before 2013, use the baseline version (nehalem)
34
- bun build --compile --target=bun-linux-x64-baseline ./index.ts --outfile myapp
35
-
36
- # To explicitly only support CPUs from 2013 and later, use the modern version (haswell)
37
- # modern is faster, but baseline is more compatible.
38
- bun build --compile --target=bun-linux-x64-modern ./index.ts --outfile myapp
39
- ```
40
-
41
- To build for Linux ARM64 (e.g. Graviton or Raspberry Pi):
42
-
43
- ```sh
44
- # Note: the default architecture is x64 if no architecture is specified.
45
- bun build --compile --target=bun-linux-arm64 ./index.ts --outfile myapp
46
- ```
47
-
48
- To build for Windows x64:
49
-
50
- ```sh
51
- bun build --compile --target=bun-windows-x64 ./path/to/my/app.ts --outfile myapp
52
-
53
- # To support CPUs from before 2013, use the baseline version (nehalem)
54
- bun build --compile --target=bun-windows-x64-baseline ./path/to/my/app.ts --outfile myapp
55
-
56
- # To explicitly only support CPUs from 2013 and later, use the modern version (haswell)
57
- bun build --compile --target=bun-windows-x64-modern ./path/to/my/app.ts --outfile myapp
58
-
59
- # note: if no .exe extension is provided, Bun will automatically add it for Windows executables
60
- ```
61
-
62
- To build for macOS arm64:
63
-
64
- ```sh
65
- bun build --compile --target=bun-darwin-arm64 ./path/to/my/app.ts --outfile myapp
66
- ```
67
-
68
- To build for macOS x64:
69
-
70
- ```sh
71
- bun build --compile --target=bun-darwin-x64 ./path/to/my/app.ts --outfile myapp
72
- ```
73
-
74
- #### Supported targets
75
-
76
- The order of the `--target` flag does not matter, as long as they're delimited by a `-`.
77
-
78
- | --target | Operating System | Architecture | Modern | Baseline | Libc |
79
- | --------------------- | ---------------- | ------------ | ------ | -------- | ----- |
80
- | bun-linux-x64 | Linux | x64 | ✅ | ✅ | glibc |
81
- | bun-linux-arm64 | Linux | arm64 | ✅ | N/A | glibc |
82
- | bun-windows-x64 | Windows | x64 | ✅ | ✅ | - |
83
- | ~~bun-windows-arm64~~ | Windows | arm64 | ❌ | ❌ | - |
84
- | bun-darwin-x64 | macOS | x64 | ✅ | ✅ | - |
85
- | bun-darwin-arm64 | macOS | arm64 | ✅ | N/A | - |
86
- | bun-linux-x64-musl | Linux | x64 | ✅ | ✅ | musl |
87
- | bun-linux-arm64-musl | Linux | arm64 | ✅ | N/A | musl |
88
-
89
- On x64 platforms, Bun uses SIMD optimizations which require a modern CPU supporting AVX2 instructions. The `-baseline` build of Bun is for older CPUs that don't support these optimizations. Normally, when you install Bun we automatically detect which version to use but this can be harder to do when cross-compiling since you might not know the target CPU. You usually don't need to worry about it on Darwin x64, but it is relevant for Windows x64 and Linux x64. If you or your users see `"Illegal instruction"` errors, you might need to use the baseline version.
90
-
91
- ## Build-time constants
92
-
93
- Use the `--define` flag to inject build-time constants into your executable, such as version numbers, build timestamps, or configuration values:
94
-
95
- ```bash
96
- $ bun build --compile --define BUILD_VERSION='"1.2.3"' --define BUILD_TIME='"2024-01-15T10:30:00Z"' src/cli.ts --outfile mycli
97
- ```
98
-
99
- These constants are embedded directly into your compiled binary at build time, providing zero runtime overhead and enabling dead code elimination optimizations.
100
-
101
- {% callout type="info" %}
102
- For comprehensive examples and advanced patterns, see the [Build-time constants guide](/guides/runtime/build-time-constants).
103
- {% /callout %}
104
-
105
- ## Deploying to production
106
-
107
- Compiled executables reduce memory usage and improve Bun's start time.
108
-
109
- Normally, Bun reads and transpiles JavaScript and TypeScript files on `import` and `require`. This is part of what makes so much of Bun "just work", but it's not free. It costs time and memory to read files from disk, resolve file paths, parse, transpile, and print source code.
110
-
111
- With compiled executables, you can move that cost from runtime to build-time.
112
-
113
- When deploying to production, we recommend the following:
114
-
115
- ```sh
116
- bun build --compile --minify --sourcemap ./path/to/my/app.ts --outfile myapp
117
- ```
118
-
119
- ### Bytecode compilation
120
-
121
- To improve startup time, enable bytecode compilation:
122
-
123
- ```sh
124
- bun build --compile --minify --sourcemap --bytecode ./path/to/my/app.ts --outfile myapp
125
- ```
126
-
127
- Using bytecode compilation, `tsc` starts 2x faster:
128
-
129
- {% image src="https://github.com/user-attachments/assets/dc8913db-01d2-48f8-a8ef-ac4e984f9763" width="689" /%}
130
-
131
- Bytecode compilation moves parsing overhead for large input files from runtime to bundle time. Your app starts faster, in exchange for making the `bun build` command a little slower. It doesn't obscure source code.
132
-
133
- **Experimental:** Bytecode compilation is an experimental feature introduced in Bun v1.1.30. Only `cjs` format is supported (which means no top-level-await). Let us know if you run into any issues!
134
-
135
- ### What do these flags do?
136
-
137
- The `--minify` argument optimizes the size of the transpiled output code. If you have a large application, this can save megabytes of space. For smaller applications, it might still improve start time a little.
138
-
139
- The `--sourcemap` argument embeds a sourcemap compressed with zstd, so that errors & stacktraces point to their original locations instead of the transpiled location. Bun will automatically decompress & resolve the sourcemap when an error occurs.
140
-
141
- The `--bytecode` argument enables bytecode compilation. Every time you run JavaScript code in Bun, JavaScriptCore (the engine) will compile your source code into bytecode. We can move this parsing work from runtime to bundle time, saving you startup time.
142
-
143
- ## Embedding runtime arguments
144
-
145
- **`--compile-exec-argv="args"`** - Embed runtime arguments that are available via `process.execArgv`:
146
-
147
- ```bash
148
- bun build --compile --compile-exec-argv="--smol --user-agent=MyBot" ./app.ts --outfile myapp
149
- ```
150
-
151
- ```js
152
- // In the compiled app
153
- console.log(process.execArgv); // ["--smol", "--user-agent=MyBot"]
154
- ```
155
-
156
- ## Act as the Bun CLI
157
-
158
- {% note %}
159
-
160
- New in Bun v1.2.16
161
-
162
- {% /note %}
163
-
164
- You can run a standalone executable as if it were the `bun` CLI itself by setting the `BUN_BE_BUN=1` environment variable. When this variable is set, the executable will ignore its bundled entrypoint and instead expose all the features of Bun's CLI.
165
-
166
- For example, consider an executable compiled from a simple script:
167
-
168
- ```sh
169
- $ cat such-bun.js
170
- console.log("you shouldn't see this");
171
-
172
- $ bun build --compile ./such-bun.js
173
- [3ms] bundle 1 modules
174
- [89ms] compile such-bun
175
- ```
176
-
177
- Normally, running `./such-bun` with arguments would execute the script. However, with the `BUN_BE_BUN=1` environment variable, it acts just like the `bun` binary:
178
-
179
- ```sh
180
- # Executable runs its own entrypoint by default
181
- $ ./such-bun install
182
- you shouldn't see this
183
-
184
- # With the env var, the executable acts like the `bun` CLI
185
- $ BUN_BE_BUN=1 ./such-bun install
186
- bun install v1.2.16-canary.1 (1d1db811)
187
- Checked 63 installs across 64 packages (no changes) [5.00ms]
188
- ```
189
-
190
- This is useful for building CLI tools on top of Bun that may need to install packages, bundle dependencies, run different or local files and more without needing to download a separate binary or install bun.
191
-
192
- ## Full-stack executables
193
-
194
- {% note %}
195
-
196
- New in Bun v1.2.17
197
-
198
- {% /note %}
199
-
200
- Bun's `--compile` flag can create standalone executables that contain both server and client code, making it ideal for full-stack applications. When you import an HTML file in your server code, Bun automatically bundles all frontend assets (JavaScript, CSS, etc.) and embeds them into the executable. When Bun sees the HTML import on the server, it kicks off a frontend build process to bundle JavaScript, CSS, and other assets.
201
-
202
- {% codetabs %}
203
-
204
- ```ts#server.ts
205
- import { serve } from "bun";
206
- import index from "./index.html";
207
-
208
- const server = serve({
209
- routes: {
210
- "/": index,
211
- "/api/hello": { GET: () => Response.json({ message: "Hello from API" }) },
212
- },
213
- });
214
-
215
- console.log(`Server running at http://localhost:${server.port}`);
216
- ```
217
-
218
- ```html#index.html
219
- <!DOCTYPE html>
220
- <html>
221
- <head>
222
- <title>My App</title>
223
- <link rel="stylesheet" href="./styles.css">
224
- </head>
225
- <body>
226
- <h1>Hello World</h1>
227
- <script src="./app.js"></script>
228
- </body>
229
- </html>
230
- ```
231
-
232
- ```js#app.js
233
- console.log("Hello from the client!");
234
- ```
235
-
236
- ```css#styles.css
237
- body {
238
- background-color: #f0f0f0;
239
- }
240
- ```
241
-
242
- {% /codetabs %}
243
-
244
- To build this into a single executable:
245
-
246
- ```sh
247
- bun build --compile ./server.ts --outfile myapp
248
- ```
249
-
250
- This creates a self-contained binary that includes:
251
-
252
- - Your server code
253
- - The Bun runtime
254
- - All frontend assets (HTML, CSS, JavaScript)
255
- - Any npm packages used by your server
256
-
257
- The result is a single file that can be deployed anywhere without needing Node.js, Bun, or any dependencies installed. Just run:
258
-
259
- ```sh
260
- ./myapp
261
- ```
262
-
263
- Bun automatically handles serving the frontend assets with proper MIME types and cache headers. The HTML import is replaced with a manifest object that `Bun.serve` uses to efficiently serve pre-bundled assets.
264
-
265
- For more details on building full-stack applications with Bun, see the [full-stack guide](/docs/bundler/fullstack).
266
-
267
- ## Worker
268
-
269
- To use workers in a standalone executable, add the worker's entrypoint to the CLI arguments:
270
-
271
- ```sh
272
- $ bun build --compile ./index.ts ./my-worker.ts --outfile myapp
273
- ```
274
-
275
- Then, reference the worker in your code:
276
-
277
- ```ts
278
- console.log("Hello from Bun!");
279
-
280
- // Any of these will work:
281
- new Worker("./my-worker.ts");
282
- new Worker(new URL("./my-worker.ts", import.meta.url));
283
- new Worker(new URL("./my-worker.ts", import.meta.url).href);
284
- ```
285
-
286
- As of Bun v1.1.25, when you add multiple entrypoints to a standalone executable, they will be bundled separately into the executable.
287
-
288
- In the future, we may automatically detect usages of statically-known paths in `new Worker(path)` and then bundle those into the executable, but for now, you'll need to add it to the shell command manually like the above example.
289
-
290
- If you use a relative path to a file not included in the standalone executable, it will attempt to load that path from disk relative to the current working directory of the process (and then error if it doesn't exist).
291
-
292
- ## SQLite
293
-
294
- You can use `bun:sqlite` imports with `bun build --compile`.
295
-
296
- By default, the database is resolved relative to the current working directory of the process.
297
-
298
- ```js
299
- import db from "./my.db" with { type: "sqlite" };
300
-
301
- console.log(db.query("select * from users LIMIT 1").get());
302
- ```
303
-
304
- That means if the executable is located at `/usr/bin/hello`, the user's terminal is located at `/home/me/Desktop`, it will look for `/home/me/Desktop/my.db`.
305
-
306
- ```
307
- $ cd /home/me/Desktop
308
- $ ./hello
309
- ```
310
-
311
- ## Embed assets & files
312
-
313
- Standalone executables support embedding files.
314
-
315
- To embed files into an executable with `bun build --compile`, import the file in your code.
316
-
317
- ```ts
318
- // this becomes an internal file path
319
- import icon from "./icon.png" with { type: "file" };
320
- import { file } from "bun";
321
-
322
- export default {
323
- fetch(req) {
324
- // Embedded files can be streamed from Response objects
325
- return new Response(file(icon));
326
- },
327
- };
328
- ```
329
-
330
- Embedded files can be read using `Bun.file`'s functions or the Node.js `fs.readFile` function (in `"node:fs"`).
331
-
332
- For example, to read the contents of the embedded file:
333
-
334
- ```js
335
- import icon from "./icon.png" with { type: "file" };
336
- import { file } from "bun";
337
-
338
- const bytes = await file(icon).arrayBuffer();
339
- // await fs.promises.readFile(icon)
340
- // fs.readFileSync(icon)
341
- ```
342
-
343
- ### Embed SQLite databases
344
-
345
- If your application wants to embed a SQLite database, set `type: "sqlite"` in the import attribute and the `embed` attribute to `"true"`.
346
-
347
- ```js
348
- import myEmbeddedDb from "./my.db" with { type: "sqlite", embed: "true" };
349
-
350
- console.log(myEmbeddedDb.query("select * from users LIMIT 1").get());
351
- ```
352
-
353
- This database is read-write, but all changes are lost when the executable exits (since it's stored in memory).
354
-
355
- ### Embed N-API Addons
356
-
357
- As of Bun v1.0.23, you can embed `.node` files into executables.
358
-
359
- ```js
360
- const addon = require("./addon.node");
361
-
362
- console.log(addon.hello());
363
- ```
364
-
365
- Unfortunately, if you're using `@mapbox/node-pre-gyp` or other similar tools, you'll need to make sure the `.node` file is directly required or it won't bundle correctly.
366
-
367
- ### Embed directories
368
-
369
- To embed a directory with `bun build --compile`, use a shell glob in your `bun build` command:
370
-
371
- ```sh
372
- $ bun build --compile ./index.ts ./public/**/*.png
373
- ```
374
-
375
- Then, you can reference the files in your code:
376
-
377
- ```ts
378
- import icon from "./public/assets/icon.png" with { type: "file" };
379
- import { file } from "bun";
380
-
381
- export default {
382
- fetch(req) {
383
- // Embedded files can be streamed from Response objects
384
- return new Response(file(icon));
385
- },
386
- };
387
- ```
388
-
389
- This is honestly a workaround, and we expect to improve this in the future with a more direct API.
390
-
391
- ### Listing embedded files
392
-
393
- To get a list of all embedded files, use `Bun.embeddedFiles`:
394
-
395
- ```js
396
- import "./icon.png" with { type: "file" };
397
- import { embeddedFiles } from "bun";
398
-
399
- console.log(embeddedFiles[0].name); // `icon-${hash}.png`
400
- ```
401
-
402
- `Bun.embeddedFiles` returns an array of `Blob` objects which you can use to get the size, contents, and other properties of the files.
403
-
404
- ```ts
405
- embeddedFiles: Blob[]
406
- ```
407
-
408
- The list of embedded files excludes bundled source code like `.ts` and `.js` files.
409
-
410
- #### Content hash
411
-
412
- By default, embedded files have a content hash appended to their name. This is useful for situations where you want to serve the file from a URL or CDN and have fewer cache invalidation issues. But sometimes, this is unexpected and you might want the original name instead:
413
-
414
- To disable the content hash, pass `--asset-naming` to `bun build --compile` like this:
415
-
416
- ```sh
417
- $ bun build --compile --asset-naming="[name].[ext]" ./index.ts
418
- ```
419
-
420
- ## Minification
421
-
422
- To trim down the size of the executable a little, pass `--minify` to `bun build --compile`. This uses Bun's minifier to reduce the code size. Overall though, Bun's binary is still way too big and we need to make it smaller.
423
-
424
- ## Using Bun.build() API
425
-
426
- You can also generate standalone executables using the `Bun.build()` JavaScript API. This is useful when you need programmatic control over the build process.
427
-
428
- ### Basic usage
429
-
430
- ```js
431
- await Bun.build({
432
- entrypoints: ["./app.ts"],
433
- outdir: "./dist",
434
- compile: {
435
- target: "bun-windows-x64",
436
- outfile: "myapp.exe",
437
- },
438
- });
439
- ```
440
-
441
- ### Windows metadata with Bun.build()
442
-
443
- When targeting Windows, you can specify metadata through the `windows` object:
444
-
445
- ```js
446
- await Bun.build({
447
- entrypoints: ["./app.ts"],
448
- outdir: "./dist",
449
- compile: {
450
- target: "bun-windows-x64",
451
- outfile: "myapp.exe",
452
- windows: {
453
- title: "My Application",
454
- publisher: "My Company Inc",
455
- version: "1.2.3.4",
456
- description: "A powerful application built with Bun",
457
- copyright: "© 2024 My Company Inc",
458
- hideConsole: false, // Set to true for GUI applications
459
- icon: "./icon.ico", // Path to icon file
460
- },
461
- },
462
- });
463
- ```
464
-
465
- ### Cross-compilation with Bun.build()
466
-
467
- You can cross-compile for different platforms:
468
-
469
- ```js
470
- // Build for multiple platforms
471
- const platforms = [
472
- { target: "bun-windows-x64", outfile: "app-windows.exe" },
473
- { target: "bun-linux-x64", outfile: "app-linux" },
474
- { target: "bun-darwin-arm64", outfile: "app-macos" },
475
- ];
476
-
477
- for (const platform of platforms) {
478
- await Bun.build({
479
- entrypoints: ["./app.ts"],
480
- outdir: "./dist",
481
- compile: platform,
482
- });
483
- }
484
- ```
485
-
486
- ## Windows-specific flags
487
-
488
- When compiling a standalone executable for Windows, there are several platform-specific options that can be used to customize the generated `.exe` file:
489
-
490
- ### Visual customization
491
-
492
- - `--windows-icon=path/to/icon.ico` - Set the executable file icon
493
- - `--windows-hide-console` - Disable the background terminal window (useful for GUI applications)
494
-
495
- ### Metadata customization
496
-
497
- You can embed version information and other metadata into your Windows executable:
498
-
499
- - `--windows-title <STR>` - Set the product name (appears in file properties)
500
- - `--windows-publisher <STR>` - Set the company name
501
- - `--windows-version <STR>` - Set the version number (e.g. "1.2.3.4")
502
- - `--windows-description <STR>` - Set the file description
503
- - `--windows-copyright <STR>` - Set the copyright information
504
-
505
- #### Example with all metadata flags:
506
-
507
- ```sh
508
- bun build --compile ./app.ts \
509
- --outfile myapp.exe \
510
- --windows-title "My Application" \
511
- --windows-publisher "My Company Inc" \
512
- --windows-version "1.2.3.4" \
513
- --windows-description "A powerful application built with Bun" \
514
- --windows-copyright "© 2024 My Company Inc"
515
- ```
516
-
517
- This metadata will be visible in Windows Explorer when viewing the file properties:
518
-
519
- 1. Right-click the executable in Windows Explorer
520
- 2. Select "Properties"
521
- 3. Go to the "Details" tab
522
-
523
- #### Version string format
524
-
525
- The `--windows-version` flag accepts version strings in the following formats:
526
-
527
- - `"1"` - Will be normalized to "1.0.0.0"
528
- - `"1.2"` - Will be normalized to "1.2.0.0"
529
- - `"1.2.3"` - Will be normalized to "1.2.3.0"
530
- - `"1.2.3.4"` - Full version format
531
-
532
- Each version component must be a number between 0 and 65535.
533
-
534
- {% callout %}
535
-
536
- These flags currently cannot be used when cross-compiling because they depend on Windows APIs. They are only available when building on Windows itself.
537
-
538
- {% /callout %}
539
-
540
- ## Code signing on macOS
541
-
542
- To codesign a standalone executable on macOS (which fixes Gatekeeper warnings), use the `codesign` command.
543
-
544
- ```sh
545
- $ codesign --deep --force -vvvv --sign "XXXXXXXXXX" ./myapp
546
- ```
547
-
548
- We recommend including an `entitlements.plist` file with JIT permissions.
549
-
550
- ```xml#entitlements.plist
551
- <?xml version="1.0" encoding="UTF-8"?>
552
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
553
- <plist version="1.0">
554
- <dict>
555
- <key>com.apple.security.cs.allow-jit</key>
556
- <true/>
557
- <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
558
- <true/>
559
- <key>com.apple.security.cs.disable-executable-page-protection</key>
560
- <true/>
561
- <key>com.apple.security.cs.allow-dyld-environment-variables</key>
562
- <true/>
563
- <key>com.apple.security.cs.disable-library-validation</key>
564
- <true/>
565
- </dict>
566
- </plist>
567
- ```
568
-
569
- To codesign with JIT support, pass the `--entitlements` flag to `codesign`.
570
-
571
- ```sh
572
- $ codesign --deep --force -vvvv --sign "XXXXXXXXXX" --entitlements entitlements.plist ./myapp
573
- ```
574
-
575
- After codesigning, verify the executable:
576
-
577
- ```sh
578
- $ codesign -vvv --verify ./myapp
579
- ./myapp: valid on disk
580
- ./myapp: satisfies its Designated Requirement
581
- ```
582
-
583
- {% callout %}
584
-
585
- Codesign support requires Bun v1.2.4 or newer.
586
-
587
- {% /callout %}
588
-
589
- ## Code splitting
590
-
591
- Standalone executables support code splitting. Use `--compile` with `--splitting` to create an executable that loads code-split chunks at runtime.
592
-
593
- ```bash
594
- $ bun build --compile --splitting ./src/entry.ts --outdir ./build
595
- ```
596
-
597
- {% codetabs %}
598
-
599
- ```ts#src/entry.ts
600
- console.log("Entrypoint loaded");
601
- const lazy = await import("./lazy.ts");
602
- lazy.hello();
603
- ```
604
-
605
- ```ts#src/lazy.ts
606
- export function hello() {
607
- console.log("Lazy module loaded");
608
- }
609
- ```
610
-
611
- {% /codetabs %}
612
-
613
- ```bash
614
- $ ./build/entry
615
- Entrypoint loaded
616
- Lazy module loaded
617
- ```
618
-
619
- ## Unsupported CLI arguments
620
-
621
- Currently, the `--compile` flag can only accept a single entrypoint at a time and does not support the following flags:
622
-
623
- - `--outdir` — use `outfile` instead (except when using with `--splitting`).
624
- - `--public-path`
625
- - `--target=node` or `--target=browser`
626
- - `--no-bundle` - we always bundle everything into the executable.