Skip to content

Commit f5aa82f

Browse files
committed
docs: rewrite docs from scratch
1 parent d3f6f71 commit f5aa82f

File tree

1 file changed

+198
-40
lines changed

1 file changed

+198
-40
lines changed

README.md

Lines changed: 198 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,231 @@
1-
> Minimal no-framework template built with Vite and React
1+
# React Starter Kit
22

3-
## Features
3+
> A minimal, flexible React template built with Vite supporting multiple rendering modes
44
5-
✔️  **Hybrid application:** Choose rendering method (SSG, SSR, SPA) based on routes
5+
## ✨ Features
66

7-
✔️  **API support:** Optional file-system routing support for API endpoints
7+
- 🔄 **Multiple Rendering Modes**: SSR, SSG, and SPA support with route-level control
8+
- 🚀 **File-based API Routes**: Build serverless APIs with simple file structure
9+
- 🎯 **Framework-agnostic**: Pure React with Vite - no complex abstractions
10+
- 🔍 **SEO Ready**: Built-in meta tags and server-side rendering for better SEO
11+
- 📦 **Universal Deployment**: Compatible with Stormkit, Netlify, Vercel and more
12+
-**Hot Module Replacement**: Instant updates during development
13+
- 🏷️ **TypeScript First**: Full TypeScript support out of the box
14+
- 🎨 **Modern Tooling**: Vite for lightning-fast builds and development
815

9-
✔️  **No framework:** React knowledge is enough to use this template
16+
## 🚀 Quick Start
1017

11-
✔️  **SEO:** SEO tags included for SSR and SSG
18+
### Installation
1219

13-
✔️  **Compatible:** Build produces separate folders for client-side, server-side, and API. Highly compatible with hosting providers.
20+
```bash
21+
# Clone or use as template
22+
git clone <repository-url>
23+
cd react-starter
1424

15-
✔️ &nbsp;**HMR:** Hot module replacement support for all apps (SSR, SSG, SPA, API)
25+
# Install dependencies
26+
npm install
27+
# or
28+
yarn install
29+
# or
30+
pnpm install
31+
```
1632

17-
✔️ &nbsp;**Typescript:** Built-in TypeScript support
33+
### Development
1834

19-
## Getting started
35+
```bash
36+
npm run dev
37+
```
2038

21-
This is a starter template for building applications with Vite and React. Click `use this template` and start working right away.
39+
Visit `http://localhost:5173` to see your app running with HMR enabled.
2240

23-
## Development
41+
## 📁 Project Structure
2442

2543
```
26-
# Using npm
44+
src/
45+
├── api/ # API routes (serverless functions)
46+
│ └── hello.ts # Example API endpoint
47+
├── pages/ # Application pages
48+
│ ├── home.tsx # Home page (SPA)
49+
│ ├── about.tsx # About page (SPA)
50+
│ └── ssr.tsx # SSR example with fetchData
51+
├── components/ # Reusable components
52+
├── context.ts # React context for data sharing
53+
├── entry-client.tsx # Client-side entry point
54+
├── entry-server.tsx # Server-side entry point
55+
├── prerender.ts # SSG route configuration
56+
└── App.tsx # Main application component
57+
```
58+
59+
## 🔧 Build Commands
60+
61+
### Development Server
62+
63+
```bash
2764
npm run dev
65+
```
66+
67+
Starts development server with HMR at `http://localhost:5173`
2868

29-
# Using yarn
30-
yarn dev
69+
### Single Page Application (SPA)
3170

32-
# Using pnpm
33-
pnpm run dev
71+
```bash
72+
npm run build:spa
3473
```
3574

36-
This will spawn an Express server that serves your application. Built-in Hot Module Replacement (HMR) support.
75+
Builds a traditional SPA. Output: `.stormkit/public/`
3776

38-
## How it works?
77+
### Server-Side Rendering (SSR)
78+
79+
```bash
80+
npm run build:ssr
81+
```
3982

40-
In the local environment, [src/entry-server.tsx](./src/entry-server.tsx) is the entry point for the application. It uses
41-
`react-router` to understand what page to render. If the route exports a `fetchData` method, the component will be server-side-rendered.
42-
Otherwise, it will be client-side rendered. Data returned by `fetchData` will be made available to the component by [React Context](./src/context.ts).
83+
Builds for serverless deployment with SSR. Output: `.stormkit/server/`
84+
85+
### Static Site Generation (SSG)
86+
87+
```bash
88+
npm run build:spa # Build SPA first
89+
npm run build:ssg # Generate static pages
90+
```
4391

44-
See [src/pages/ssr.tsx](./src/pages/ssr.tsx) for an example.
92+
Pre-renders specified routes at build time. Output: `.stormkit/public/`
4593

46-
## Static site generator
94+
### API Only
95+
96+
```bash
97+
npm run build:api
98+
```
99+
100+
Builds only the API functions. Output: `.stormkit/api/`
101+
102+
## 🎯 Rendering Modes
103+
104+
### Single Page Application (Default)
105+
106+
All routes are client-side rendered by default:
107+
108+
```tsx
109+
// src/pages/home.tsx
110+
export default function Home() {
111+
return <h1>Welcome to Home</h1>;
112+
}
113+
```
114+
115+
### Server-Side Rendering
116+
117+
Add a `fetchData` export to enable SSR:
118+
119+
```tsx
120+
// src/pages/ssr.tsx
121+
export async function fetchData() {
122+
const data = await fetch("https://api.example.com/data");
123+
return data.json();
124+
}
125+
126+
export default function SSRPage({ data }: { data: any }) {
127+
return <h1>Server-rendered: {data.title}</h1>;
128+
}
129+
```
47130

48-
You can define which routes to prerender by modifying the [src/prerender.ts](./src/prerender.ts) file. During build time, the builder will be make a
49-
request to each route exported by this file and will take a snapshot of the HTML document.
131+
### Static Site Generation
50132

51-
## Single page app
133+
Configure routes to pre-render in `src/prerender.ts`:
134+
135+
```tsx
136+
// src/prerender.ts
137+
export default [{ path: "/" }, { path: "/about" }, { path: "/blog/post-1" }];
138+
```
139+
140+
## 🔌 API Routes
141+
142+
Create API endpoints by adding files to `src/api/`:
143+
144+
```typescript
145+
// src/api/hello.ts
146+
export default function handler(request: Request) {
147+
return new Response(JSON.stringify({ message: "Hello, World!" }), {
148+
headers: { "Content-Type": "application/json" },
149+
});
150+
}
151+
```
152+
153+
Access at: `http://localhost:5173/api/hello`
154+
155+
### Dynamic API Routes
156+
157+
```typescript
158+
// src/api/users/[id].ts
159+
export default function handler(request: Request) {
160+
const url = new URL(request.url);
161+
const id = url.pathname.split("/").pop();
162+
163+
return new Response(JSON.stringify({ userId: id }), {
164+
headers: { "Content-Type": "application/json" },
165+
});
166+
}
167+
```
168+
169+
## 🚀 Deployment
170+
171+
### Stormkit
172+
173+
Import this application on Stormkit (either self-hosted or cloud) and simply click deploy. It works with zero-config.
174+
175+
### Static Hosting
176+
177+
```bash
178+
npm run build:spa
179+
npm run build:ssg # Optional: for pre-rendered pages
180+
```
181+
182+
Deploy the `.stormkit/public` folder.
183+
184+
## 🔧 Configuration
185+
186+
### Vite Configuration
187+
188+
- `vite.config.ts` - Development server
189+
- `vite.config.ssr.ts` - SSR build
190+
- `vite.config.spa.ts` - SPA build
191+
- `vite.config.api.ts` - API build
192+
193+
## 🛠️ Advanced Usage
194+
195+
### Custom Server
196+
197+
```typescript
198+
// server.ts
199+
import { handler } from "./.stormkit/server/server.mjs";
200+
201+
const server = express();
202+
server.use(handler);
203+
server.listen(3000);
204+
```
52205

53-
By default, every route is a single-page application.
206+
## 🤝 Contributing
54207

55-
## API
208+
1. Fork the repository
209+
2. Create your feature branch: `git checkout -b feature/amazing-feature`
210+
3. Commit your changes: `git commit -m 'Add amazing feature'`
211+
4. Push to the branch: `git push origin feature/amazing-feature`
212+
5. Open a Pull Request
56213

57-
The [src/api/](./src/api/) directory contains functions that act as API. The path to the file and the file name is used to determine the endpoint.
58-
The API is comptabile with [Stormkit](https://www.stormkit.io). [Check the docs](https://www.stormkit.io/docs/features/writing-api) for more information.
214+
## 📚 Resources
59215

60-
If you need to host the API elsewhere, you'll need to change the [vite.config.api.ts](./vite.config.api.ts) file and create a bundle from it. You may
61-
also need to write an entry point that calls the appropriate function based on the route.
216+
- [Vite Documentation](https://vitejs.dev/)
217+
- [React Documentation](https://react.dev/)
218+
- [Stormkit Documentation](https://stormkit.io/docs)
62219

63-
## Community
220+
## 🌟 Showcase
64221

65-
Here's a curated list of websites using this framework. Please feel free to add your own:
222+
Websites built with this template:
66223

67-
| Site name | Description |
68-
| -------------------------------------- | ------------------------------------------------------ |
69-
| [Stormkit.io](https://www.stormkit.io) | Deploy full stack javascript applications on the cloud |
224+
| Site | Description | Features Used |
225+
| -------------------------------------------------------- | --------------------------------- | --------------- |
226+
| [Stormkit.io](https://stormkit.io) | Deploy full-stack JavaScript apps | SSR, API Routes |
227+
| [Add your site](https://github.com/your-repo/issues/new) | Submit your project | - |
70228

71-
## License
229+
## 📄 License
72230

73-
MIT
231+
MIT ©

0 commit comments

Comments
 (0)