React + Vite Local Development Guide

Create a React project with Vite, start a hot-reloading development server at localhost:5173, and build production static assets.


React + Vite is currently the most popular combination for local React development: Vite provides ultra-fast cold starts and HMR, while React handles the UI. It is suitable for single-page applications (SPAs), component libraries, and small to medium-sized frontend projects.

Quick Start

npm create vite@latest my-app -- --template react-ts
cd my-app
npm install
npm run dev

Default localhost Access

PurposeAddress
Development Serverhttp://localhost:5173
Preview Production Buildhttp://localhost:4173 (npm run preview)

You can modify server.port and server.host in vite.config.ts.

Common Commands

CommandDescription
npm run devStart the development server
npm run buildOutput to dist/
npm run previewPreview the build results locally

Coordinating with Backend APIs

During development, you can configure a proxy in vite.config.ts to avoid cross-origin issues in the browser:

export default defineConfig({
  server: {
    proxy: {
      '/api': 'http://localhost:8080',
    },
  },
});

Frontend requests to /api/users will be forwarded to the backend running on port 8080.

Summary

React + Vite is quick to get started with and provides smooth hot reloading. You can debug locally at http://localhost:5173. For production, deploy the dist/ directory to static hosting services like NGINX or Cloudflare Pages.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run