examples/solid/start-bun/README.md
An optimized production server for TanStack Start applications using Bun, implementing intelligent static asset loading with configurable memory management.
This project was created with TanStack Start:
bunx create-start-app@latest
Install dependencies:
bun install
For development:
bun run dev
Build the application for production:
bun run build
You can easily use this production server in your own TanStack Start project:
server.ts file into your project rootbun run buildbun run server.ts
Or add it to your package.json scripts:
{
"scripts": {
"start": "bun run server.ts"
}
}
Then run with:
bun run start
The server.ts implements a high-performance production server with the following features:
The server automatically decides which files to preload into memory and which to serve on-demand:
# Server Port (default: 3000)
PORT=3000
# Maximum file size for in-memory loading (in bytes, default: 5MB)
STATIC_PRELOAD_MAX_BYTES=5242880
# Include patterns (comma-separated, only these files will be preloaded)
STATIC_PRELOAD_INCLUDE="*.js,*.css,*.woff2"
# Exclude patterns (comma-separated, these files will be excluded)
STATIC_PRELOAD_EXCLUDE="*.map,*.txt"
# Enable detailed logging
STATIC_PRELOAD_VERBOSE=true
# Preload only critical assets
STATIC_PRELOAD_MAX_BYTES=1048576 \
STATIC_PRELOAD_INCLUDE="*.js,*.css" \
STATIC_PRELOAD_EXCLUDE="*.map,vendor-*" \
bun run start
# Preload all small assets
STATIC_PRELOAD_MAX_BYTES=10485760 \
bun run start
# With detailed logging
STATIC_PRELOAD_VERBOSE=true \
bun run start
The server displays a clear overview of all loaded assets at startup:
š¦ Loading static assets from ./dist/client...
Max preload size: 5.00 MB
Include patterns: *.js,*.css,*.woff2
š Preloaded into memory:
/assets/index-a1b2c3d4.js 45.23 kB ā gzip: 15.83 kB
/assets/index-e5f6g7h8.css 12.45 kB ā gzip: 4.36 kB
š¾ Served on-demand:
/assets/vendor-i9j0k1l2.js 245.67 kB ā gzip: 86.98 kB
ā
Preloaded 2 files (57.68 KB) into memory
ā¹ļø 1 files will be served on-demand (1 too large, 0 filtered)
š Server running at http://localhost:3000
This project uses Vitest for testing. You can run the tests with:
bun run test
This project uses Tailwind CSS for styling.
This project uses eslint and prettier for linting and formatting. Eslint is configured using tanstack/eslint-config. The following scripts are available:
bun run lint
bun run format
bun run check