diff --git a/docs/runtime/modules.md b/docs/runtime/modules.md index 2d50ac6cdd2c40..526446751ea295 100644 --- a/docs/runtime/modules.md +++ b/docs/runtime/modules.md @@ -238,6 +238,30 @@ If `exports` is not defined, Bun falls back to `"module"` (ESM imports only) the } ``` +### Custom conditions + +The `--conditions` flag allows you to specify a list of conditions to use when resolving packages from package.json `"exports"`. + +This flag is supported in both `bun build` and Bun's runtime. + +```sh +# Use it with bun build: +$ bun build --conditions="react-server" --target=bun ./app/foo/route.js + +# Use it with bun's runtime: +$ bun --conditions="react-server" ./app/foo/route.js +``` + +You can also use `conditions` programmatically with `Bun.build`: + +```js +await Bun.build({ + conditions: ["react-server"], + target: "bun", + entryPoints: ["./app/foo/route.js"], +}); +``` + ## Path re-mapping In the spirit of treating TypeScript as a first-class citizen, the Bun runtime will re-map import paths according to the [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) field in `tsconfig.json`. This is a major divergence from Node.js, which doesn't support any form of import path re-mapping.