Skip to content

Commit 7729ea3

Browse files
committed
wip - bun docs update
1 parent 30273db commit 7729ea3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

packages/varlock-website/src/components/ExecCommandWidget.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const { command, showBinary = true, dlx = false } = Astro.props;
2323
<TabItem label="vlt">
2424
<Code code={`${dlx ? "vlx" : "vlx --"} ${command}`} lang="bash" />
2525
</TabItem>
26+
<TabItem label="bun">
27+
<Code code={`${dlx ? "bunx" : "bun run"} ${command}`} lang="bash" />
28+
</TabItem>
2629
{
2730
showBinary && (
2831
<TabItem label="standalone binary">

packages/varlock-website/src/components/InstallJsDepsWidget.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ const packagesStr = Array.isArray(packages) ? packages.join(" ") : packages;
3636
lang="bash"
3737
/>
3838
</TabItem>
39+
<TabItem label="bun">
40+
<Code
41+
code={`bun ${remove ? "remove" : "add"} ${dev ? "-D " : ""}${packagesStr}`}
42+
lang="bash"
43+
/>
44+
</TabItem>
3945
</Tabs>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Bun
3+
description: How to integrate Varlock with a Bun-powered JavaScript project
4+
---
5+
import { TabItem, Tabs } from "@astrojs/starlight/components";
6+
import ExecCommandWidget from '@/components/ExecCommandWidget.astro';
7+
8+
For the most part, Varlock just works with Bun the same way it works with Node.js, and other JavaScript integrations work the same way.
9+
10+
11+
### Conflicts with Bun's .env loading
12+
Bun does its own automatic loading of `.env` files, based on the current value of `NODE_ENV` (or `BUN_ENV`), which it defaults to `development` if not set. This causes problems when bun decides to load `.env.development` and passes those env vars into varlock.
13+
14+
The best way to fix this is to disable bun's automatic loading of `.env` files in your `bunfig.toml` file:
15+
```diff lang="toml" title="bunfig.toml"
16+
+env = false
17+
```
18+
19+
You may also use the `--no-env-file` CLI flag when invoking scripts with `bun`/`bunx`.
20+
21+
Note that if you are building a standalone executable using `bun build`, you can use the `--no-compile-autoload-dotenv` flag to disable this behavior in the final executable.
22+
23+
24+
### Using a preload script
25+
One option we have with bun is to use a [preload script](https://bun.com/docs/runtime/bunfig#preload), configured in `bunfig.toml`. If you do this, you will no longer have to use `bun run varlock run -- yourscript` or use `import 'varlock/auto-load'` in your code!
26+
27+
```diff lang="toml" title="bunfig.toml"
28+
+preload = ["varlock/auto-load"]
29+
```
30+
31+
:::caution[Do not use with framework integrations]
32+
Note that you should not do this if using a framework integration, as those integrations watch your `.env` files to trigger live-reloading.
33+
:::

0 commit comments

Comments
 (0)