A minimal, flexible React template built with Vite supporting multiple rendering modes
- π Multiple Rendering Modes: SSR, SSG, and SPA support with route-level control
- π File-based API Routes: Build serverless APIs with simple file structure
- π― Framework-agnostic: Pure React with Vite - no complex abstractions
- π SEO Ready: Built-in meta tags and server-side rendering for better SEO
- π¦ Universal Deployment: Compatible with Stormkit, Netlify, Vercel and more
- β‘ Hot Module Replacement: Instant updates during development
- π·οΈ TypeScript First: Full TypeScript support out of the box
- π¨ Modern Tooling: Vite for lightning-fast builds and development
# Clone or use as template git clone <repository-url> cd react-starter # Install dependencies npm install # or yarn install # or pnpm installnpm run devVisit http://localhost:5173 to see your app running with HMR enabled.
src/ βββ api/ # API routes (serverless functions) β βββ hello.ts # Example API endpoint βββ pages/ # Application pages β βββ home.tsx # Home page (SPA) β βββ about.tsx # About page (SPA) β βββ ssr.tsx # SSR example with fetchData βββ components/ # Reusable components βββ context.ts # React context for data sharing βββ entry-client.tsx # Client-side entry point βββ entry-server.tsx # Server-side entry point βββ prerender.ts # SSG route configuration βββ App.tsx # Main application component npm run devStarts development server with HMR at http://localhost:5173
npm run build:spaBuilds a traditional SPA. Output: .stormkit/public/
npm run build:ssrBuilds for serverless deployment with SSR. Output: .stormkit/server/
npm run build:spa # Build SPA first npm run build:ssg # Generate static pagesPre-renders specified routes at build time. Output: .stormkit/public/
npm run build:apiBuilds only the API functions. Output: .stormkit/api/
All routes are client-side rendered by default:
// src/pages/home.tsx export default function Home() { return <h1>Welcome to Home</h1>; }Add a fetchData export to enable SSR:
import { useContext } from "react"; import Context from "~/context"; // src/pages/ssr.tsx export async function fetchData() { const data = await fetch("https://api.example.com/data"); return { head: { // meta tags }, context: { myParam: data.myParam; } }; } export default function SSRPage({ data }: { data: any }) { const context = useContext(Context); return <h1>Server-rendered: {data.myParam}</h1>; }Configure routes to pre-render in src/prerender.ts:
// src/prerender.ts // Export an array of paths to be prerendered. export default ["/", "/about", "/blog/post-1"];Create API endpoints by adding files to src/api/:
// src/api/hello.ts export default async (req: http.IncomingMessage, res: http.ServerResponse) => { res.setHeader("Content-Type", "application/json"); res.writeHead(200, "Success"); res.write( JSON.stringify({ payload: "This is an API function - can be deployed as a serverless function!", }) ); res.end(); };Access at: http://localhost:5173/api/hello
Import this application on Stormkit (either self-hosted or cloud) and simply click deploy. It works with zero-config.
npm run build:spa npm run build:ssg # Optional: for pre-rendered pagesDeploy the .stormkit/public folder.
vite.config.ts- Development servervite.config.ssr.ts- SSR buildvite.config.spa.ts- SPA buildvite.config.api.ts- API build
// server.ts import { handler } from "./.stormkit/server/server.mjs"; const server = express(); server.use(handler); server.listen(3000);- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Websites built with this template:
| Site | Description | Features Used |
|---|---|---|
| Stormkit.io | Deploy full-stack JavaScript apps | SSR, API Routes |
| Add your site | Submit your project | - |
MIT Β©