Update executables.md

This commit is contained in:
Jarred Sumner
2024-02-25 23:45:52 -08:00
parent 92dec0a871
commit e2ee5642e0

View File

@@ -32,6 +32,26 @@ All imported files and packages are bundled into the executable, along with a co
{% /callout %}
## Deploying to production
Compiled executables reduce memory usage and improve Bun's start time.
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.
You can do all that work ahead of time with compiled executables, and move that cost from runtime to build-time.
When deploying to production, we recommend the following:
```sh
bun build --compile --minify --sourcemap ./path/to/my/app.ts --outfile myapp
```
##### What's happening here?
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.
The `--sourcemap` argument generates a sourcemap, so that errors & stacktraces point to their original locations instead of the transpiled location. Sourcemaps tend to be large, but we store them compressed with zstd and defer decompressing it until the first time an error occurs.
## SQLite
You can use `bun:sqlite` imports with `bun build --compile`.