Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Build and Deploy — Deploy to Vercel

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:

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:

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 .gitignore The file already contains node_modules and dist. 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

  1. Access the vercel.com, sign up/log in with your GitHub account
  2. Click "New Project" → Import Git Repository → select the blog-app repository
  3. Vercel automatically recognizes the project as Vite (Vue), requiring no configuration
  4. Click "Deploy", wait a few dozen seconds, and the build completes
  5. 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:

  1. Detects a new commit in the repository
  2. Pulls the latest code and runs npm install
  3. Runs npm run build to build
  4. 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.

  1. In the Vercel project Dashboard → Settings → Domains
  2. Enter your domain (e.g., blog.runoob.com)
  3. Follow the prompts to add a CNAME record at your DNS provider pointing to cname.vercel-dns.com
  4. 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