Skip to content

jerryxfu/vite-react-ts

Repository files navigation

Vite + React + TypeScript Template

An opinionated starter template for React projects with TypeScript, Vite, and Sass.

What's Included

  • React with react-router-dom (lazy loading, error boundary)
  • TypeScript with strict mode
  • Sass (SCSS) with a minimal reset and CSS custom properties (light/dark via prefers-color-scheme)
  • ESLint flat config with typescript-eslint, react-hooks, and react-refresh plugins
  • pnpm as the enforced package manager

Project Structure

src/
├── components/
│   └── ErrorBoundary.tsx
├── pages/
│   ├── Home
│   ├── About
│   └── NotFound
├── index.scss
└── main.tsx

Getting Started

pnpm install
pnpm dev

Scripts

Command Description
pnpm dev Start dev server
pnpm build Lint, type-check, and build
pnpm preview Preview production build locally
pnpm lint Run ESLint
pnpm lint:fix Run ESLint with auto-fix

Customization

  • Styles: Edit src/index.scss to change the color palette, fonts, or add variables. Add individual component-level .scss files as you expand the site.
  • Routing: Add new pages in src/pages/ and register routes in main.tsx. Use lazy() + <Suspense> for code-split routes.
  • Context providers: Wrap <RouterProvider /> in main.tsx with any context providers you need (e.g. theme, auth).

React + TypeScript + Vite (generated by create-vite)

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

React Compiler

The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.

Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

export default defineConfig([
    globalIgnores(['dist']),
    {
        files: ['**/*.{ts,tsx}'],
        extends: [
            // Other configs...

            // Remove tseslint.configs.recommended and replace with this
            tseslint.configs.recommendedTypeChecked,
            // Alternatively, use this for stricter rules
            tseslint.configs.strictTypeChecked,
            // Optionally, add this for stylistic rules
            tseslint.configs.stylisticTypeChecked,

            // Other configs...
        ],
        languageOptions: {
            parserOptions: {
                project: ['./tsconfig.node.json', './tsconfig.app.json'],
                tsconfigRootDir: import.meta.dirname,
            },
            // other options...
        },
    },
])

You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:

// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default defineConfig([
    globalIgnores(['dist']),
    {
        files: ['**/*.{ts,tsx}'],
        extends: [
            // Other configs...
            // Enable lint rules for React
            reactX.configs['recommended-typescript'],
            // Enable lint rules for React DOM
            reactDom.configs.recommended,
        ],
        languageOptions: {
            parserOptions: {
                project: ['./tsconfig.node.json', './tsconfig.app.json'],
                tsconfigRootDir: import.meta.dirname,
            },
            // other options...
        },
    },
])

About

Template for a Vite React Typescript website

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors