Build and Deploy — Deploy to Vercel
In this chapter you will learn how to package the locally developed blog project and deploy it to the internet for free, obtaining a public access link.
Build the Production Bundle
During development, run npm run dev, and Vite starts a local development server with hot module replacement.
But for deployment, you need optimized, small-sized files — that is the production build.
$ npm run build
After running it, a dist/ folder is generated in the project root:
dist/
├── index.html # 入口 HTML(资源引用已被替换为构建后的路径)
├── assets/
│ ├── index-Df3aBc9x.js # 打包后的 JS(代码已压缩、tree-shaking)
│ ├── index-Gh7jKl2m.css # 打包后的 CSS(已提取、压缩)
│ └── ... # 其他资源
├── posts.json # public 目录的文件原样复制
└── favicon.ico # 其他静态资源
Note a few key changes:
- File names include a hash (e.g.,
Df3aBc9x), the hash changes when the content changes, used for browser cache control - The code is minified and tree-shaken (unused code removed)
- JS and CSS are split into separate files
public/The contents of the directory are copied as-is to the root
To preview the build result, you can run
npx vite preview, which starts a server locally in production mode to simulate the online environment.
Push the Project to GitHub
Deployment platforms (such as Vercel) usually pull code from a Git repository and build automatically, so you need to upload the project to GitHub first.
Step 1: Create a GitHub Repository
On the GitHub website, click the + sign in the top-right corner → New repository, and fill in:
- Repository name:blog-app
- Set it to Public (free deployment)
- Do not check "Initialize this repository with a README" (since the local project files already exist)
Step 2: Initialize Git Locally and Push
$ cd blog-app
$ git init
$ git add .
$ git commit -m "初始化博客项目"
$ git branch -M main
$ git remote add origin https://github.com/你的用户名/blog-app.git
$ git push -u origin main
After a successful push, refresh the GitHub page to see all project files.
Before Pushing, Confirm
.gitignoreThe file already containsnode_modulesanddist. node_modules should not be uploaded (it can be restored via npm install), and dist should be auto-generated by the build platform.
Deploy in Vercel
Vercel is currently the most popular frontend deployment platform, with zero-config support for Vue/Vite projects.
Deployment Steps
- Access the vercel.com, sign up/log in with your GitHub account
- Click "New Project" → Import Git Repository → select the blog-app repository
- Vercel automatically recognizes the project as Vite (Vue), requiring no configuration
- Click "Deploy", wait a few dozen seconds, and the build completes
- After successful deployment, you get a link like:
https://blog-app.vercel.app
| Configuration Item | Value | Description |
|---|---|---|
| Framework Preset | Vite | Auto-detect |
| Build Command | npm run build | Auto-detect |
| Output Directory | dist | Auto-detect |
| Root Directory | ./ | Default project root |
Auto-deploy
From then on, whenever you modify code locally and push to GitHub (git push), Vercel automatically:
- Detects a new commit in the repository
- Pulls the latest code and runs npm install
- Runs npm run build to build
- Deploys to the production environment
The whole process requires no manual operation; push means go live.
Custom Domain (Optional)
Vercel provides .vercel.app as a free subdomain, or you can bind your own domain.
- In the Vercel project Dashboard → Settings → Domains
- Enter your domain (e.g., blog.runoob.com)
- Follow the prompts to add a CNAME record at your DNS provider pointing to
cname.vercel-dns.com - Wait for DNS to take effect (usually a few minutes to a few hours); Vercel will automatically apply for an SSL certificate
Next Learning Directions
You have mastered the core skills of Vue 3; below are advanced paths based on different goals:
| Learning Direction | Who It's For | Recommended Starting Point |
|---|---|---|
| TypeScript + Vue3 | Want to write more rigorous large-scale projects | Add TS type definitions to the project, starting from props and store |
| Nuxt.js | Need SEO or server-side rendering | A full-stack framework based on Vue 3, with file-based routing and automatic SSR |
| VueUse | Want to use ready-made Composables | Vue's officially recommended collection of composable functions, containing 200+ utility functions |
| Component Library | Quickly build an admin dashboard | Element Plus, Naive UI, Ant Design Vue |