You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/start/framework/react/hosting.md
+74-7Lines changed: 74 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,10 +202,10 @@ npm run start
202
202
Make sure that your `react` and `react-dom` packages are set to version 19.0.0 or higher in your `package.json` file. If not, run the following command to upgrade the packages:
Then you can run the following command to build and start your application:
221
+
#### Production Server with Bun
222
+
223
+
To run TanStack Start applications in production with Bun, you need a custom server implementation. The default build output doesn't work directly with `bun run dist/server/server.js`.
224
+
225
+
We've created an optimized production server that provides intelligent static asset loading with configurable memory management.
226
+
227
+
**Features:**
228
+
229
+
-**Hybrid loading strategy**: Small files (<5MB by default) are preloaded into memory, large files are served on-demand
230
+
-**Configurable file filtering**: Use include/exclude patterns to control which files are preloaded
231
+
-**Production-ready caching headers**: Automatic optimization for static assets
1. Copy the [`server.ts`](https://github.com/magnusmay/tanstack-start-bun-hosting/blob/main/server.ts) file from the example repository to your project root
237
+
238
+
2. Build your application:
239
+
240
+
```sh
241
+
bun run build
242
+
```
243
+
244
+
3. Start the optimized server:
245
+
246
+
```sh
247
+
bun run server.ts
248
+
```
249
+
250
+
**Configuration:**
251
+
252
+
The server can be configured using environment variables:
222
253
223
254
```sh
224
-
bun run build
255
+
# Basic usage
256
+
bun run server.ts
257
+
258
+
# Custom port
259
+
PORT=8080 bun run server.ts
260
+
261
+
# Optimize for minimal memory usage (1MB preload limit)
262
+
STATIC_PRELOAD_MAX_BYTES=1048576 bun run server.ts
263
+
264
+
# Preload only critical assets
265
+
STATIC_PRELOAD_INCLUDE="*.js,*.css" \
266
+
STATIC_PRELOAD_EXCLUDE="*.map,vendor-*" \
267
+
bun run server.ts
268
+
269
+
# Debug mode with verbose logging
270
+
STATIC_PRELOAD_VERBOSE=true bun run server.ts
225
271
```
226
272
227
-
You're now ready to deploy your application to a Bun server. You can start your application by running:
273
+
**Environment Variables:**
228
274
229
-
```sh
230
-
bun run .output/server/index.mjs
275
+
-`PORT`: Server port (default: 3000)
276
+
-`STATIC_PRELOAD_MAX_BYTES`: Maximum file size to preload in bytes (default: 5242880 = 5MB)
277
+
-`STATIC_PRELOAD_INCLUDE`: Comma-separated glob patterns for files to include
278
+
-`STATIC_PRELOAD_EXCLUDE`: Comma-separated glob patterns for files to exclude
279
+
-`STATIC_PRELOAD_VERBOSE`: Enable detailed logging (set to "true")
For a complete example and more details, check out the [TanStack Start + Bun Hosting repository](https://github.com/magnusmay/tanstack-start-bun-hosting).
0 commit comments