diff --git a/docs/api/import-meta.md b/docs/api/import-meta.md index 37f35884d77e59..2c821f751015df 100644 --- a/docs/api/import-meta.md +++ b/docs/api/import-meta.md @@ -38,6 +38,11 @@ import.meta.resolveSync("zod") --- +- `import.meta.env` +- An alias to `process.env`. + +--- + - `import.meta.resolve{Sync}` - Resolve a module specifier (e.g. `"zod"` or `"./file.tsx"`) to an absolute path. While file would be imported if the specifier were imported from this file? diff --git a/docs/runtime/env.md b/docs/runtime/env.md index e38eabffd0adb8..887c5ab7ab0a71 100644 --- a/docs/runtime/env.md +++ b/docs/runtime/env.md @@ -25,6 +25,16 @@ Or programmatically by assigning a property to `process.env`. process.env.FOO = "hello"; ``` +### Manually specifying `.env` files + +Bun supports `--env-file` to override which specific `.env` file to load. You can use `--env-file` when running scripts in bun's runtime, or when running package.json scripts. + +```sh +bun --env-file=.env.1 src/index.ts + +bun --env-file=.env.abc --env-file=.env.def run build +``` + ### Quotation marks Bun supports double quotes, single quotes, and @@ -75,10 +85,11 @@ The current environment variables can be accessed via `process.env`. process.env.API_TOKEN; // => "secret" ``` -Bun also exposes these variables via `Bun.env`, which is a simple alias of `process.env`. +Bun also exposes these variables via `Bun.env` and `import.meta.env`, which is a simple alias of `process.env`. ```ts Bun.env.API_TOKEN; // => "secret" +import.meta.env.API_TOKEN; // => "secret" ``` To print all currently-set environment variables to the command line, run `bun run env`. This is useful for debugging.