From 05f68d79c8ea5b40aaee609638a2824b41bbee9b Mon Sep 17 00:00:00 2001 From: Michael H Date: Thu, 10 Oct 2024 22:04:58 +1100 Subject: [PATCH] docs: `--conditions` flag (#14463) --- docs/runtime/modules.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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.