Build and Deploy — Deploy to Vercel
In this chapter you will learn how to package your 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, Vite starts a local development server with hot reload support.
What you need for deployment is an optimized and minified production build.
$ npm run build
After execution, the project root directory generates dist/ folder is generated in the project root:
dist/
├── index.html # 入口 HTML
├── assets/
│ ├── index-Df3aBc9x.js # 打包压缩后的 JS
│ ├── index-Gh7jKl2m.css # 提取并压缩后的 CSS
│ └── ...
├── posts.json # public 目录文件原样复制
└── favicon.svg # 静态资源
Key changes:
- File names include a hash (when content changes the hash changes, used for browser cache control)
- Code is minified and Tree-shaken (unused code removed)
- Contents of the public/ directory are copied as-is to the root directory
Preview the build result: run
npx vite preview, start a service locally in production mode to simulate the online environment.
Push the Project to GitHub
Step 1: Create a GitHub Repository
On GitHub click + → New repository, fill in:
- Repository name:react-blog-app
- Set it to Public (free deployment)
- Do not check Initialize with README
Step 2: Initialize Git and Push
$ cd blog-app
$ git init
$ git add .
$ git commit -m "初始化 React 博客项目"
$ git branch -M main
$ git remote add origin https://github.com/你的用户名/react-blog-app.git
$ git push -u origin main
Before Pushing, Confirm
.gitignoreContainsnode_modulesanddist. node_modules should not be uploaded (it can be restored via npm install), and dist is automatically generated by the build platform.
Vercel Deployment
Vercel is currently the most popular front-end deployment platform, with zero-configuration support for React/Vite projects.
Deployment Steps
- Access the vercel.com, log in with your GitHub account
- Click "New Project" → Import Git Repository → select react-blog-app
- Vercel automatically detects Vite + React and fills in the configuration
- Click "Deploy" and wait a few dozen seconds
- After a successful deployment, you get a link like:
https://react-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 |
Auto-deploy
After this, every time you git push, Vercel automatically: pulls the code → npm install → npm run build → deploys online.
The entire process is fully automated; pushing means going live.
Custom Domain (Optional)
- Vercel project Dashboard → Settings → Domains
- Enter your domain (e.g., blog.runoob.com)
- Add a CNAME record at your DNS provider pointing to
cname.vercel-dns.com - Wait for DNS to take effect; Vercel automatically applies for an SSL certificate
Next Learning Directions
| Learning Direction | Who It's For | Recommended Starting Point |
|---|---|---|
| TypeScript + React | Want to write more rigorous large-scale projects | Add TypeScript to the project, starting with Props and Hook types |
| Next.js | Need SEO, SSR, and full-stack capabilities | A React-based full-stack framework where files are routes |
| React Query (TanStack Query) | Need more powerful data fetching management | Caching, automatic refetching, optimistic updates |
| State management library | Application state logic is very complex | Zustand (lightweight), Redux Toolkit (heavyweight) |
| Component Library | Quickly build an admin dashboard | Ant Design、MUI、shadcn/ui |
React vs Vue3 Full-Stack Route Comparison
| Direction | React Ecosystem | Vue3 Ecosystem |
|---|---|---|
| Full-stack Framework | Next.js | Nuxt.js |
| Type system | TypeScript (better native support) | TypeScript |
| State Management (lightweight) | Zustand | Pinia |
| Data Fetching | React Query | VueUse / TanStack Query |
| Mobile | React Native | — (Weex is no longer maintained) |
You have completed the most important step - building a complete real project with React. Whether it's TypeScript or Next.js later on, they all add dimensions on top of what you already have. React's way of thinking (state-driven views, componentization, unidirectional data flow) will play a role in every subsequent project you work on.