diff options
author | 2023-08-25 04:31:21 -0700 | |
---|---|---|
committer | 2023-08-25 04:32:20 -0700 | |
commit | f839640c17730d6f623eeb2eefdbc3d0f45088c1 (patch) | |
tree | e01f2986b5b5a7975f161ee7db58a769261ecbca /docs | |
parent | 557e912d9a9914bd1962ef632d146f760f5ffa39 (diff) | |
download | bun-f839640c17730d6f623eeb2eefdbc3d0f45088c1.tar.gz bun-f839640c17730d6f623eeb2eefdbc3d0f45088c1.tar.zst bun-f839640c17730d6f623eeb2eefdbc3d0f45088c1.zip |
Update executables.md
Diffstat (limited to 'docs')
-rw-r--r-- | docs/bundler/executables.md | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/bundler/executables.md b/docs/bundler/executables.md index 9a0fc639e..fcfd014ef 100644 --- a/docs/bundler/executables.md +++ b/docs/bundler/executables.md @@ -31,3 +31,26 @@ All imported files and packages are bundled into the executable, along with a co - `--publicPath` {% /callout %} + +# Embedding files + +Standalone executables support embedding files. + +To embed files into an executable with `bun build --compile`, import the file in your code + +```js +// this becomes an internal file path +import icon from "./icon.png"; + +import { file } from "bun"; + +export default { + fetch(req) { + return new Response(file(icon)); + }, +}; +``` + +You may need to specify a `--loader` for it to be treated as a `"file"` loader (so you get back a file path). + +Embedded files can be read using `Bun.file`'s functions or the Node.js `fs.readFile` function (in `"node:fs"`). |