diff --git a/docs/bundler/fullstack.mdx b/docs/bundler/fullstack.mdx index 6b108d9866..c28241d8ba 100644 --- a/docs/bundler/fullstack.mdx +++ b/docs/bundler/fullstack.mdx @@ -492,6 +492,28 @@ Bun will lazily resolve and load each plugin and use them to bundle your routes. the CLI. +## Inline Environment Variables + +Bun can replace `process.env.*` references in your frontend JavaScript and TypeScript with their actual values at build time. Configure the `env` option in your `bunfig.toml`: + +```toml title="bunfig.toml" icon="settings" +[serve.static] +env = "PUBLIC_*" # only inline env vars starting with PUBLIC_ (recommended) +# env = "inline" # inline all environment variables +# env = "disable" # disable env var replacement (default) +``` + + + This only works with literal `process.env.FOO` references, not `import.meta.env` or indirect access like `const env = + process.env; env.FOO`. + +If an environment variable is not set, you may see runtime errors like `ReferenceError: process + is not defined` in the browser. + + + +See the [HTML & static sites documentation](/bundler/html-static#inline-environment-variables) for more details on build-time configuration and examples. + ## How It Works Bun uses `HTMLRewriter` to scan for `