You have built components, wired up routing, and centralized state with Pinia. The last step is getting your application in front of real users. In this lesson you'll learn what a production build actually does, how to configure it, and how to deploy the result to popular hosts like Netlify, Vercel, and GitHub Pages, including the one server tweak every SPA needs.
During development, Vite serves your source files with instant hot reload. That is great for you but wasteful for visitors. A production build transforms the project into a small set of optimized static files:
index-a1b2c3.js so browsers can cache them forever.Run the build with:
npm run buildThe output lands in a dist/ folder. You can inspect it locally before deploying:
npm run previewThis serves dist/ on a local port so you can verify the production bundle behaves exactly like the dev version.
Hardcoding API URLs is a common beginner mistake. Vite exposes variables that start with VITE_ to your client code:
# .env.production
VITE_API_URL=https://api.example.comconst api = import.meta.env.VITE_API_URL
const res = await fetch(api + '/products')Never put secrets like private API keys in these variables. Everything shipped to the browser is public; secrets belong on a backend server.
If you use createWebHistory from the routing lesson, a visitor who refreshes on /users/42 asks the server for a file called /users/42, which does not exist. The fix is a rewrite rule that serves index.html for every path and lets Vue Router take over. On Netlify, create a _redirects file in your public/ folder:
/* /index.html 200Vercel and most other hosts have an equivalent rewrite setting; on your own Nginx server use try_files $uri $uri/ /index.html;.
Both platforms follow the same flow:
npm run build and the output directory to dist.From then on, every push to your main branch triggers a fresh build and deploy automatically. Pull requests even get their own preview URLs, which makes reviewing changes with teammates painless.
GitHub Pages serves your site from a subpath like https://user.github.io/my-app/, so Vite needs to know the base path:
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
base: '/my-app/'
})Then build and publish the dist/ folder to the gh-pages branch, either manually or with a GitHub Actions workflow that runs on every push.
npm run build locally and fix any warnings.<title> and meta description in index.html./about survive a page refresh.npm run build produces an optimized static dist/ folder; npm run preview tests it locally.VITE_ environment variables for configuration and keep secrets on the server.index.html for all routes.npm run build and output dist.base option in vite.config.js when hosted under a subpath.Congratulations, you have completed the Vue.js course! A great next step is exploring server-side rendering with Nuxt, or revisiting any lesson in this series to solidify the fundamentals.