Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/solid/start-bun/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
count.txt
.env
.nitro
.tanstack
.output
.vinxi
todos.json
3 changes: 3 additions & 0 deletions examples/solid/start-bun/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package-lock.json
pnpm-lock.yaml
yarn.lock
11 changes: 11 additions & 0 deletions examples/solid/start-bun/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.watcherExclude": {
"**/routeTree.gen.ts": true
},
"search.exclude": {
"**/routeTree.gen.ts": true
},
"files.readonlyInclude": {
"**/routeTree.gen.ts": true
}
}
173 changes: 173 additions & 0 deletions examples/solid/start-bun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# TanStack Start + Bun Production Server

An optimized production server for TanStack Start applications using Bun, implementing intelligent static asset loading with configurable memory management.

## 🚀 Features

- **Hybrid Loading Strategy**: Small files are preloaded into memory, large files are served on-demand
- **Configurable File Filtering**: Include/Exclude patterns for precise control
- **Memory-efficient Response Generation**: Optimized for high performance
- **Production-ready Caching Headers**: Automatic Cache-Control headers for optimal performance
- **Detailed Logging**: Vite-like output for better overview

## 📦 Installation

This project was created with TanStack Start:

```bash
bunx create-start-app@latest
```

Install dependencies:

```bash
bun install
```

## 🏃‍♂️ Development

For development:

```bash
bun run dev
```

## 🔨 Production Build

Build the application for production:

```bash
bun run build
```

## 🚀 Production Server with server.ts

### Quick Start - Use in Your Project

You can easily use this production server in your own TanStack Start project:

1. **Copy the `server.ts` file** into your project root
2. **Build your project** with `bun run build`
3. **Start the server** directly with:
```bash
bun run server.ts
```

Or add it to your `package.json` scripts:

```json
{
"scripts": {
"start": "bun run server.ts"
}
}
```

Then run with:

```bash
bun run start
```

### Server Features

The `server.ts` implements a high-performance production server with the following features:

#### 1. Intelligent Asset Loading

The server automatically decides which files to preload into memory and which to serve on-demand:

- **In-Memory Loading**: Small files (default < 5MB) are loaded into memory at startup
- **On-Demand Loading**: Large files are loaded from disk only when requested
- **Optimized Performance**: Frequently used assets are served from memory

#### 2. Configuration via Environment Variables

```bash
# 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
```

### Example Configurations

#### Minimal Memory Footprint

```bash
# Preload only critical assets
STATIC_PRELOAD_MAX_BYTES=1048576 \
STATIC_PRELOAD_INCLUDE="*.js,*.css" \
STATIC_PRELOAD_EXCLUDE="*.map,vendor-*" \
bun run start
```

#### Maximum Performance

```bash
# Preload all small assets
STATIC_PRELOAD_MAX_BYTES=10485760 \
bun run start
```

#### Debug Mode

```bash
# With detailed logging
STATIC_PRELOAD_VERBOSE=true \
bun run start
```

### Server Output

The server displays a clear overview of all loaded assets at startup:

```txt
📦 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
```

## Testing

This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:

```bash
bun run test
```

## Styling

This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.

## Linting & Formatting

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:

```bash
bun run lint
bun run format
bun run check
```
5 changes: 5 additions & 0 deletions examples/solid/start-bun/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @ts-check

import { tanstackConfig } from '@tanstack/eslint-config'

export default [...tanstackConfig]
41 changes: 41 additions & 0 deletions examples/solid/start-bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "tanstack-solid-start-bun-hosting",
"private": true,
"type": "module",
"scripts": {
"dev": "vite dev --port 3000",
"start": "bun run server.ts",
"build": "vite build",
"serve": "vite preview",
"test": "vitest run",
"lint": "eslint",
"format": "prettier",
"check": "prettier --write . && eslint --fix"
},
"dependencies": {
"@tailwindcss/vite": "^4.1.13",
"@tanstack/solid-devtools": "^0.7.0",
"@tanstack/solid-router": "^1.135.2",
"@tanstack/solid-router-devtools": "^1.135.2",
"@tanstack/solid-router-ssr-query": "^1.135.2",
"@tanstack/solid-start": "^1.135.2",
"@tanstack/router-plugin": "^1.135.2",
"solid-js": "^1.9.10",
"tailwindcss": "^4.1.13",
"vite-tsconfig-paths": "^5.1.4"
},
"devDependencies": {
"@tanstack/eslint-config": "^0.3.2",
"@testing-library/dom": "^10.4.1",
"@solidjs/testing-library": "^0.8.10",
"@types/bun": "^1.2.22",
"@types/node": "22.10.2",
"vite-plugin-solid": "^2.11.10",
"jsdom": "^27.0.0",
"prettier": "^3.6.2",
"typescript": "^5.9.2",
"vite": "^7.1.7",
"vitest": "^3.2.4",
"web-vitals": "^5.1.0"
}
}
10 changes: 10 additions & 0 deletions examples/solid/start-bun/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

/** @type {import('prettier').Config} */
const config = {
semi: false,
singleQuote: true,
trailingComma: 'all',
}

export default config
Binary file added examples/solid/start-bun/public/favicon.ico
Binary file not shown.
25 changes: 25 additions & 0 deletions examples/solid/start-bun/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "TanStack App",
"name": "Create TanStack App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions examples/solid/start-bun/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
Loading
Loading