aboutsummaryrefslogtreecommitdiff
path: root/docs/cli
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-05-09 00:55:21 -0400
committerGravatar GitHub <noreply@github.com> 2023-05-08 21:55:21 -0700
commit5e366872f659abf116b903e5cece999a04cd018b (patch)
treed06b5ccd28ea49a7a5e050868ff27e676e0d56f7 /docs/cli
parent1a411e201b71374f515d1f6cdbb1b36186ee48b0 (diff)
downloadbun-5e366872f659abf116b903e5cece999a04cd018b.tar.gz
bun-5e366872f659abf116b903e5cece999a04cd018b.tar.zst
bun-5e366872f659abf116b903e5cece999a04cd018b.zip
implement build api `define` and `loaders` (#2805)
* parse error logs * clean up types * remove --jsx-production. use NODE_ENV instead * add define to js api * add loaders to js api * fixups * sourcemap * typo fix * remove label, comment dir just for now * test tweaks * test work * make optional enums actually optional. allows `sourcemap: undefined` * overload host ram test * string tests * tests * test for 2815 * requested changes * sort this list * remove this test file now that it passes * oops * add --format * finish ts tests * doc typos related to define and loader
Diffstat (limited to 'docs/cli')
-rw-r--r--docs/cli/build.md74
1 files changed, 71 insertions, 3 deletions
diff --git a/docs/cli/build.md b/docs/cli/build.md
index f205969d5..01262944d 100644
--- a/docs/cli/build.md
+++ b/docs/cli/build.md
@@ -324,7 +324,7 @@ Depending on the target, Bun will apply different module resolution rules and op
{% /table %}
-<!-- ### `module`
+### `format`
Specifies the module format to be used in the generated bundles.
@@ -714,6 +714,24 @@ var value = z.string().parse("Hello world!")
console.log(_.upperCase(value));
```
+To mark all imports as external, use the wildcard `*`:
+
+{% codetabs %}
+
+```ts#JavaScript
+await Bun.build({
+ entrypoints: ['./index.tsx'],
+ outdir: './out',
+ external: ['*'],
+})
+```
+
+```bash#CLI
+$ bun build ./index.tsx --outdir ./out --external '*'
+```
+
+{% /codetabs %}
+
### `naming`
Customizes the generated file names. Defaults to `./[dir]/[name].[ext]`.
@@ -988,6 +1006,56 @@ The output file would now look something like this.
+ var logo = 'https://cdn.example.com/logo-a7305bdef.svg';
```
+### `define`
+
+A map of global identifiers to be replaced at build time. Keys of this object are identifier names, and values are JSON strings that will be inlined.
+
+{% callout }
+This is not needed to inline `process.env.NODE_ENV`, as Bun does this automatically.
+{% /callout %}
+
+{% codetabs %}
+
+```ts#JavaScript
+await Bun.build({
+ entrypoints: ['./index.tsx'],
+ outdir: './out',
+ define: {
+ STRING: JSON.stringify("value"),
+ "nested.boolean": "true",
+ },
+})
+```
+
+```bash#CLI
+$ bun build ./index.tsx --outdir ./out --define 'STRING="value"' --define "nested.boolean=true"
+```
+
+{% /codetabs %}
+
+### `loader`
+
+A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain file files are loaded.
+
+{% codetabs %}
+
+```ts#JavaScript
+await Bun.build({
+ entrypoints: ['./index.tsx'],
+ outdir: './out',
+ loader: {
+ ".png": "dataurl",
+ ".txt": "file",
+ },
+})
+```
+
+```bash#CLI
+$ bun build ./index.tsx --outdir ./out --loader .png:dataurl --loader .txt:file
+```
+
+{% /codetabs %}
+
## Reference
```ts
@@ -1003,8 +1071,8 @@ interface BuildOptions {
outdir?: string; // default: no write (in-memory only)
target?: "browser" | "bun" | "node"; // "browser"
splitting?: boolean; // true
- plugins?: BunPlugin[]; // []
- loader?: { [k in string]: Loader };
+ plugins?: BunPlugin[]; // [] // See https://bun.sh/docs/bundler/plugins
+ loader?: { [k in string]: Loader }; // See https://bun.sh/docs/bundler/loaders
manifest?: boolean; // false
external?: string[]; // []
sourcemap?: "none" | "inline" | "external"; // "none"