Skip to content

Commit 5302896

Browse files
authored
docs(solid-start): start-bun example (#5816)
1 parent 864a2e0 commit 5302896

24 files changed

+1542
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local
6+
count.txt
7+
.env
8+
.nitro
9+
.tanstack
10+
.output
11+
.vinxi
12+
todos.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package-lock.json
2+
pnpm-lock.yaml
3+
yarn.lock
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"files.watcherExclude": {
3+
"**/routeTree.gen.ts": true
4+
},
5+
"search.exclude": {
6+
"**/routeTree.gen.ts": true
7+
},
8+
"files.readonlyInclude": {
9+
"**/routeTree.gen.ts": true
10+
}
11+
}

examples/solid/start-bun/README.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# TanStack Start + Bun Production Server
2+
3+
An optimized production server for TanStack Start applications using Bun, implementing intelligent static asset loading with configurable memory management.
4+
5+
## 🚀 Features
6+
7+
- **Hybrid Loading Strategy**: Small files are preloaded into memory, large files are served on-demand
8+
- **Configurable File Filtering**: Include/Exclude patterns for precise control
9+
- **Memory-efficient Response Generation**: Optimized for high performance
10+
- **Production-ready Caching Headers**: Automatic Cache-Control headers for optimal performance
11+
- **Detailed Logging**: Vite-like output for better overview
12+
13+
## 📦 Installation
14+
15+
This project was created with TanStack Start:
16+
17+
```bash
18+
bunx create-start-app@latest
19+
```
20+
21+
Install dependencies:
22+
23+
```bash
24+
bun install
25+
```
26+
27+
## 🏃‍♂️ Development
28+
29+
For development:
30+
31+
```bash
32+
bun run dev
33+
```
34+
35+
## 🔨 Production Build
36+
37+
Build the application for production:
38+
39+
```bash
40+
bun run build
41+
```
42+
43+
## 🚀 Production Server with server.ts
44+
45+
### Quick Start - Use in Your Project
46+
47+
You can easily use this production server in your own TanStack Start project:
48+
49+
1. **Copy the `server.ts` file** into your project root
50+
2. **Build your project** with `bun run build`
51+
3. **Start the server** directly with:
52+
```bash
53+
bun run server.ts
54+
```
55+
56+
Or add it to your `package.json` scripts:
57+
58+
```json
59+
{
60+
"scripts": {
61+
"start": "bun run server.ts"
62+
}
63+
}
64+
```
65+
66+
Then run with:
67+
68+
```bash
69+
bun run start
70+
```
71+
72+
### Server Features
73+
74+
The `server.ts` implements a high-performance production server with the following features:
75+
76+
#### 1. Intelligent Asset Loading
77+
78+
The server automatically decides which files to preload into memory and which to serve on-demand:
79+
80+
- **In-Memory Loading**: Small files (default < 5MB) are loaded into memory at startup
81+
- **On-Demand Loading**: Large files are loaded from disk only when requested
82+
- **Optimized Performance**: Frequently used assets are served from memory
83+
84+
#### 2. Configuration via Environment Variables
85+
86+
```bash
87+
# Server Port (default: 3000)
88+
PORT=3000
89+
90+
# Maximum file size for in-memory loading (in bytes, default: 5MB)
91+
STATIC_PRELOAD_MAX_BYTES=5242880
92+
93+
# Include patterns (comma-separated, only these files will be preloaded)
94+
STATIC_PRELOAD_INCLUDE="*.js,*.css,*.woff2"
95+
96+
# Exclude patterns (comma-separated, these files will be excluded)
97+
STATIC_PRELOAD_EXCLUDE="*.map,*.txt"
98+
99+
# Enable detailed logging
100+
STATIC_PRELOAD_VERBOSE=true
101+
```
102+
103+
### Example Configurations
104+
105+
#### Minimal Memory Footprint
106+
107+
```bash
108+
# Preload only critical assets
109+
STATIC_PRELOAD_MAX_BYTES=1048576 \
110+
STATIC_PRELOAD_INCLUDE="*.js,*.css" \
111+
STATIC_PRELOAD_EXCLUDE="*.map,vendor-*" \
112+
bun run start
113+
```
114+
115+
#### Maximum Performance
116+
117+
```bash
118+
# Preload all small assets
119+
STATIC_PRELOAD_MAX_BYTES=10485760 \
120+
bun run start
121+
```
122+
123+
#### Debug Mode
124+
125+
```bash
126+
# With detailed logging
127+
STATIC_PRELOAD_VERBOSE=true \
128+
bun run start
129+
```
130+
131+
### Server Output
132+
133+
The server displays a clear overview of all loaded assets at startup:
134+
135+
```txt
136+
📦 Loading static assets from ./dist/client...
137+
Max preload size: 5.00 MB
138+
Include patterns: *.js,*.css,*.woff2
139+
140+
📁 Preloaded into memory:
141+
/assets/index-a1b2c3d4.js 45.23 kB │ gzip: 15.83 kB
142+
/assets/index-e5f6g7h8.css 12.45 kB │ gzip: 4.36 kB
143+
144+
💾 Served on-demand:
145+
/assets/vendor-i9j0k1l2.js 245.67 kB │ gzip: 86.98 kB
146+
147+
✅ Preloaded 2 files (57.68 KB) into memory
148+
ℹ️ 1 files will be served on-demand (1 too large, 0 filtered)
149+
150+
🚀 Server running at http://localhost:3000
151+
```
152+
153+
## Testing
154+
155+
This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:
156+
157+
```bash
158+
bun run test
159+
```
160+
161+
## Styling
162+
163+
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
164+
165+
## Linting & Formatting
166+
167+
This project uses [eslint](https://eslint.org/) and [prettier](https://prettier.io/) for linting and formatting. Eslint is configured using [tanstack/eslint-config](https://tanstack.com/config/latest/docs/eslint). The following scripts are available:
168+
169+
```bash
170+
bun run lint
171+
bun run format
172+
bun run check
173+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @ts-check
2+
3+
import { tanstackConfig } from '@tanstack/eslint-config'
4+
5+
export default [...tanstackConfig]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "tanstack-solid-start-bun-hosting",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite dev --port 3000",
7+
"start": "bun run server.ts",
8+
"build": "vite build",
9+
"serve": "vite preview",
10+
"test": "vitest run",
11+
"lint": "eslint",
12+
"format": "prettier",
13+
"check": "prettier --write . && eslint --fix"
14+
},
15+
"dependencies": {
16+
"@tailwindcss/vite": "^4.1.13",
17+
"@tanstack/solid-devtools": "^0.7.0",
18+
"@tanstack/solid-router": "^1.135.2",
19+
"@tanstack/solid-router-devtools": "^1.135.2",
20+
"@tanstack/solid-router-ssr-query": "^1.135.2",
21+
"@tanstack/solid-start": "^1.135.2",
22+
"@tanstack/router-plugin": "^1.135.2",
23+
"solid-js": "^1.9.10",
24+
"tailwindcss": "^4.1.13",
25+
"vite-tsconfig-paths": "^5.1.4"
26+
},
27+
"devDependencies": {
28+
"@tanstack/eslint-config": "^0.3.2",
29+
"@testing-library/dom": "^10.4.1",
30+
"@solidjs/testing-library": "^0.8.10",
31+
"@types/bun": "^1.2.22",
32+
"@types/node": "22.10.2",
33+
"vite-plugin-solid": "^2.11.10",
34+
"jsdom": "^27.0.0",
35+
"prettier": "^3.6.2",
36+
"typescript": "^5.9.2",
37+
"vite": "^7.1.7",
38+
"vitest": "^3.2.4",
39+
"web-vitals": "^5.1.0"
40+
}
41+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
3+
/** @type {import('prettier').Config} */
4+
const config = {
5+
semi: false,
6+
singleQuote: true,
7+
trailingComma: 'all',
8+
}
9+
10+
export default config
3.78 KB
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "TanStack App",
3+
"name": "Create TanStack App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

0 commit comments

Comments
 (0)