You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A minimal, flexible React template built with Vite supporting multiple rendering modes
β¨ Features
π 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
π Quick Start
Installation
# Clone or use as template
git clone <repository-url>cd react-starter
# Install dependencies
npm install
# or
yarn install
# or
pnpm install
Development
npm run dev
Visit https://localhost:5173 to see your app running with HMR enabled.
π Project Structure
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
π§ Build Commands
Development Server
npm run dev
Starts development server with HMR at https://localhost:5173
Single Page Application (SPA)
npm run build:spa
Builds a traditional SPA. Output: .stormkit/public/
Server-Side Rendering (SSR)
npm run build:ssr
Builds for serverless deployment with SSR. Output: .stormkit/server/
Static Site Generation (SSG)
npm run build:spa # Build SPA first
npm run build:ssg # Generate static pages
Pre-renders specified routes at build time. Output: .stormkit/public/
API Only
npm run build:api
Builds only the API functions. Output: .stormkit/api/
π― Rendering Modes
Single Page Application (Default)
All routes are client-side rendered by default:
// src/pages/home.tsxexportdefaultfunctionHome(){return<h1>Welcome to Home</h1>;}
Server-Side Rendering
Add a fetchData export to enable SSR:
import{useContext}from"react";importContextfrom"~/context";// src/pages/ssr.tsxexportasyncfunctionfetchData(){constdata=awaitfetch("https://api.example.com/data");return{head: {// meta tags},context: {myParam: data.myParam;}};}exportdefaultfunctionSSRPage({ data }: {data: any}){constcontext=useContext(Context);return<h1>Server-rendered: {data.myParam}</h1>;}
Static Site Generation
Configure routes to pre-render in src/prerender.ts:
// src/prerender.ts// Export an array of paths to be prerendered.exportdefault["/","/about","/blog/post-1"];
π API Routes
Create API endpoints by adding files to src/api/:
// src/api/hello.tsexportdefaultasync(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: https://localhost:5173/api/hello
π Deployment
Stormkit
Import this application on Stormkit (either self-hosted or cloud) and simply click deploy. It works with zero-config.
Static Hosting
npm run build:spa
npm run build:ssg # Optional: for pre-rendered pages