Building for Production
Vite.
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.
{
"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.
- Bundle
- Remove unused
- Minify
- Split chunks
- 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.
| key | value |
|---|---|
| Output | dist/ |
| Hosts | Netlify, Vercel |
| Also | Cloudflare, GitHub Pages |
| Router | fallback 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