一个完整的部署指南,帮助你将学术作品集网站部署到各种平台。
# 检查 Node.js 版本 (需要 16+)
node --version
# 检查 npm 版本
npm --version
# 本地构建测试
npm run build
npm run preview-
修改管理员密码
// 编辑 src/components/Header.jsx 第 44 行 const correctPassword = 'your-secure-password';
-
更新个人信息
- 编辑
src/data/content.js - 或通过管理面板更新
- 编辑
-
创建 GitHub 仓库
git init git add . git commit -m "Initial commit" git branch -M main git remote add origin https://github.com/yourusername/your-repo.git git push -u origin main
-
配置 GitHub Pages
- 进入仓库 Settings → Pages
- Source 选择 "GitHub Actions"
- 项目已包含自动部署配置
-
部署工作流
- 推送代码后自动触发构建
- 构建完成后自动部署到 GitHub Pages
- 访问
https://yourusername.github.io/your-repo
-
添加 CNAME 文件
echo "your-domain.com" > public/CNAME
-
DNS 配置
- 添加 CNAME 记录指向
yourusername.github.io - 或添加 A 记录指向 GitHub Pages IP
- 添加 CNAME 记录指向
-
HTTPS 设置
- GitHub Pages 自动提供 HTTPS
- 在仓库设置中启用 "Enforce HTTPS"
-
连接仓库
- 访问 vercel.com
- 点击 "New Project"
- 导入 GitHub 仓库
-
构建配置
{ "buildCommand": "npm run build", "outputDirectory": "dist", "installCommand": "npm install" } -
环境变量 (如需要)
- 在 Vercel 控制台设置
- 用于 API 密钥等敏感信息
-
添加域名
- 在 Vercel 项目设置中添加域名
- 配置 DNS 记录
-
SSL 证书
- Vercel 自动提供 SSL 证书
- 支持自动续期
-
构建项目
npm run build
-
上传 dist 文件夹
- 访问 netlify.com
- 拖拽
dist文件夹到部署区域
-
连接仓库
- 选择 "New site from Git"
- 连接 GitHub 仓库
-
构建设置
Build command: npm run build Publish directory: dist -
重定向配置
# public/_redirects /* /index.html 200
-
安装 Firebase CLI
npm install -g firebase-tools firebase login
-
初始化 Firebase
firebase init hosting
-
配置文件
{ "hosting": { "public": "dist", "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], "rewrites": [ { "source": "**", "destination": "/index.html" } ] } }
# 构建项目
npm run build
# 部署到 Firebase
firebase deploy# 构建阶段
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
# 生产阶段
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]# nginx.conf
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
# 缓存静态资源
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
}# 构建镜像
docker build -t academic-portfolio .
# 运行容器
docker run -p 80:80 academic-portfolio# .env.production
VITE_API_URL=https://api.yourdomain.com
VITE_ANALYTICS_ID=your-analytics-id// webpack.config.js 优化配置
module.exports = {
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
};// 使用 CDN 加速静态资源
const cdnUrl = 'https://cdn.yourdomain.com';
module.exports = {
output: {
publicPath: process.env.NODE_ENV === 'production' ? cdnUrl : '/',
},
};-
Lighthouse
npm install -g lighthouse lighthouse https://yourdomain.com
-
Bundle Analyzer
npm install --save-dev webpack-bundle-analyzer npm run build -- --analyze
-
图片优化
- 使用 WebP 格式
- 启用懒加载
- 使用 CDN 服务
-
代码分割
- 路由级别分割
- 组件懒加载
- 第三方库分离
-
缓存策略
- 静态资源长期缓存
- HTML 文件短期缓存
- API 响应缓存
构建失败
# 清理缓存
rm -rf node_modules package-lock.json
npm install
# 检查依赖版本
npm audit
npm audit fix部署后空白页面
- 检查构建输出目录
- 确认路由配置正确
- 查看浏览器控制台错误
静态资源 404
- 检查 publicPath 配置
- 确认文件路径正确
- 验证服务器配置
-
本地模拟生产环境
npm run build npm run preview
-
检查构建输出
ls -la dist/
-
网络调试
- 使用浏览器开发者工具
- 检查网络请求状态
- 查看响应头信息
-
HTTPS 强制
- 所有平台都启用 HTTPS
- 配置 HSTS 头部
- 使用安全的 Cookie 设置
-
内容安全策略
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline';">
-
访问控制
- 定期更换管理员密码
- 监控异常访问
- 设置访问日志
-
备份策略
- 定期导出数据
- 多地备份存储
- 版本控制管理
-
隐私保护
- 不在代码中存储敏感信息
- 使用环境变量
- 定期清理日志
-
性能监控
- 页面加载时间
- 资源加载状态
- 用户交互响应
-
错误监控
- JavaScript 错误
- 网络请求失败
- 资源加载失败
-
用户分析
- 访问量统计
- 用户行为分析
- 设备和浏览器分布
-
定期更新
- 依赖包更新
- 安全补丁应用
- 功能优化升级
-
备份计划
- 每周数据备份
- 重要节点版本备份
- 灾难恢复测试
-
性能优化
- 定期性能测试
- 资源使用分析
- 用户体验优化
-
文档资源
- 查看项目 README
- 阅读相关技术文档
- 搜索常见问题解答
-
社区支持
- GitHub Issues
- 技术论坛讨论
- 开发者社区
-
专业服务
- 技术咨询服务
- 定制开发需求
- 部署运维支持
最后更新: 2024年3月
维护状态: 积极维护中 🚀