Building for Production
What you'll learn: How to transform your development React app into optimized files ready for real users.
From Development to Production
While you've been working with npm run dev, Vite has been serving your code in a developer-friendly way—unoptimized, with lots of helpful debugging tools. But real users need something different: fast, small files that load quickly.
The Build Command
Running npm run build tells Vite to create a production build. Think of it like packing a suitcase: you remove everything unnecessary, fold things efficiently, and make it as compact as possible for the journey.
npm run build
This command does several optimizations automatically:
- Minifies your JavaScript (removes whitespace, shortens variable names)
- Bundles multiple files into fewer chunks
- Tree-shakes unused code away
- Optimizes images and assets
- Generates unique filenames with hashes for cache control
The dist/ Folder
After the build completes, you'll see a new dist/ folder (short for "distribution"). This contains your entire app as static files—HTML, JavaScript, CSS, and assets—all ready to upload to any web host.
These files are what you deploy to services like Netlify, Vercel, GitHub Pages, or your own server. The host simply serves them; no Node.js required on the server.
Testing Before Deploy
You can preview your production build locally:
npm run preview
This simulates how your app will behave in production.
Key Takeaway: npm run build transforms your development code into optimized, deployment-ready static files in the dist/ folder that can be hosted anywhere.