aboutsummaryrefslogtreecommitdiff
path: root/docs/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'docs/runtime')
-rw-r--r--docs/runtime/hot.md16
-rw-r--r--docs/runtime/plugins.md14
2 files changed, 27 insertions, 3 deletions
diff --git a/docs/runtime/hot.md b/docs/runtime/hot.md
index 547728f4d..96571453c 100644
--- a/docs/runtime/hot.md
+++ b/docs/runtime/hot.md
@@ -10,14 +10,20 @@ $ bun --hot server.ts
Starting from the entrypoint (`server.ts` in the example above), Bun builds a registry of all imported source files (excluding those in `node_modules`) and watches them for changes. When a change is detected, Bun performs a "soft reload". All files are re-evaluated, but all global state (notably, the `globalThis` object) is persisted.
```ts#server.ts
+// make TypeScript happy
+declare global {
+ var count: number;
+}
+
globalThis.count = globalThis.count ?? 0;
console.log(`Reloaded ${globalThis.count} times`);
globalThis.count++;
+// prevent `bun run` from exiting
setInterval(function () {}, 1000000);
```
-If you run this file with `bun --hot server.ts`, you'll see the reload count increment every time you save the file. The call to `setInterval` is there to prevent the process from exiting.
+If you run this file with `bun --hot server.ts`, you'll see the reload count increment every time you save the file.
```bash
$ bun --hot index.ts
@@ -53,7 +59,13 @@ Unlike an explicit call to `Bun.serve`, the object-based syntax works out of the
For more fine-grained control, you can use the `Bun.serve` API directly and handle the server reloading manually.
```ts#server.ts
-import type {Serve} from "bun";
+import type {Serve, Server} from "bun";
+
+// make TypeScript happy
+declare global {
+ var count: number;
+ var server: Server;
+}
globalThis.count = globalThis.count ?? 0;
globalThis.count++;
diff --git a/docs/runtime/plugins.md b/docs/runtime/plugins.md
index de8885507..911d0ba1d 100644
--- a/docs/runtime/plugins.md
+++ b/docs/runtime/plugins.md
@@ -19,7 +19,15 @@ plugin({
});
```
-To consume this plugin, import it at the top of your project's entrypoint, before any application code is imported.
+To consume this plugin, add this file to the `preload` option in your [`bunfig.toml`](/docs/project/configuration). Bun automatically loads the files/modules specified in `preload` before running a file.
+
+```toml
+preload = ["./yamlPlugin.ts"]
+```
+
+{% details summary="Usage eithout preload" %}
+
+Alternatively, you can import this file manually at the top of your project's entrypoint, before any application code is imported.
```ts#app.ts
import "./yamlPlugin.ts";
@@ -28,6 +36,10 @@ import { config } from "./config.yml";
console.log(config);
```
+{% /details %}
+
+## Third party plugins
+
By convention, third-party plugins intended for consumption should export a factory function that accepts some configuration and returns a plugin object.
```ts