AI Hints
Home›React Tutorial›Testing and Shipping
React · Lesson 83 of 120

Building for Production

Vite.

⏱ 2 min read▶ Video at 1:10:35🎓 Free
Watch this lesson in the React courseWatch on YouTube ↗Full React course

During development, Vite serves your code quickly, with instant updates. For real users, you build an optimized version. Small, fast files, ready to put on any web host.

  • Dev server
  • Build for users
  • Small, fast files

The scripts

A Vite project has three main scripts. Dev starts the development server. Build creates the production files, in the dist folder. And preview serves that build locally, so you can check it before deploying.

package.jsonjson
{
  "name": "northwind-shop",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}

What a build does

The build bundles every file together. It removes unused code, minifies what's left, and splits it into chunks. Then it writes static files that any host can serve.

  1. Bundle
  2. Remove unused
  3. Minify
  4. Split chunks
  5. dist/

Deploying

The dist folder is plain HTML, CSS, and JavaScript. Upload it to a static host, like Netlify, Vercel, Cloudflare Pages, or GitHub Pages. For a router app, send unknown paths back to index dot html.

keyvalue
Outputdist/
HostsNetlify, Vercel
AlsoCloudflare, GitHub Pages
Routerfallback to index.html

Summary

Run vite build, and deploy the dist folder to a static host. Next, server components.

Key takeaways
  • npm run build
  • dist/
  • Static host
Next up: Server Components — the idea