A modern, production-ready template for building React applications with TypeScript and Vite, including a comprehensive set of libraries and tools.
- βοΈ React 18 - Latest version with concurrent features
- π TypeScript - Type safety and better developer experience
- β‘ Vite - Lightning-fast HMR and build tool
- π» Zustand - Lightweight state management with persistence support
- π Axios - Promise-based HTTP client with interceptors
- π React Query - Powerful data synchronization for React
- π React Router v6 - Declarative routing for React
- π React Hook Form - Performant, flexible forms with easy validation
- β Zod - TypeScript-first schema validation
- π¨ Tailwind CSS - Utility-first CSS framework
- π― Custom Components - Pre-built Button, Input components
- π Dark Mode - Built-in dark mode support
- π§ͺ Vitest - Fast unit testing framework
- π§© Testing Library - React Testing Library for component tests
- π ESLint - Code linting with TypeScript support
- β¨ Prettier - Code formatting with Tailwind plugin
- π date-fns - Modern date utility library
- π§ Custom Hooks - useDebounce, useLocalStorage, and more
- π οΈ Helper Functions - Formatters, class name utilities
- π Path Aliases - Import with
@/prefix
.
βββ src/
β βββ components/ # Reusable components
β βββ hooks/ # Custom React hooks
β βββ utils/ # Utility functions
β βββ types/ # TypeScript type definitions
β βββ test/ # Test setup and utilities
β βββ App.tsx # Main App component
β βββ main.tsx # Application entry point
β βββ index.css # Global styles
βββ public/ # Static assets
βββ index.html # HTML template
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ vite.config.ts # Vite configuration
βββ README.md # This file
- Node.js (v18 or higher recommended)
- npm, yarn, or pnpm
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run previewnpm run dev- Start development server at http://localhost:3000npm run build- Build for productionnpm run preview- Preview production buildnpm run lint- Run ESLintnpm run lint:fix- Run ESLint and auto-fix issuesnpm run format- Format code with Prettiernpm run format:check- Check code formattingnpm test- Run tests with Vitestnpm run test:ui- Run tests with UInpm run test:coverage- Generate test coverage report
Create a .env file based on .env.example:
cp .env.example .envAccess environment variables in your code:
const apiUrl = import.meta.env.VITE_API_URLThe template includes path alias configuration for cleaner imports:
// Instead of
import Component from '../../../components/Component'
// You can use
import Component from '@/components/Component'Example store with persistence:
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
interface Store {
count: number
increment: () => void
}
export const useStore = create<Store>()(
persist(
(set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
}),
{ name: 'my-storage' }
)
)The template includes a configured Axios instance in src/lib/api.ts with:
- Request/response interceptors
- Auth token handling
- Error handling
- Base URL configuration
TypeScript is configured with strict mode enabled. Modify tsconfig.json to adjust settings.
Vite configuration is in vite.config.ts. The template includes:
- React plugin
- Path aliases
- Test configuration
- Build optimizations
This template comes with Tailwind CSS pre-configured with:
- Custom color palette
- Dark mode support
- Prettier plugin for class sorting
- PostCSS with autoprefixer
Edit tailwind.config.js to customize colors, spacing, fonts, etc.
The template includes a cn() utility for conditional class names:
import { cn } from '@/utils/cn'
<div className={cn('base-class', isActive && 'active-class', className)} />The template includes Vitest and React Testing Library with example tests:
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Button } from './components/Button'
describe('Button', () => {
it('calls onClick when clicked', async () => {
const handleClick = vi.fn()
const user = userEvent.setup()
render(<Button onClick={handleClick}>Click me</Button>)
await user.click(screen.getByText('Click me'))
expect(handleClick).toHaveBeenCalledOnce()
})
})Run tests:
npm test # Run tests in watch mode
npm run test:ui # Run tests with UI
npm run test:coverage # Generate coverage reportnpm run buildThe build output will be in the dist/ directory, ready to be deployed to any static hosting service.
This template works with any static hosting service:
- Vercel:
vercel - Netlify:
netlify deploy - GitHub Pages: Configure with GitHub Actions
- AWS S3: Upload
dist/folder
Feel free to customize this template for your needs!
MIT