Skip to content

Commit 18e091c

Browse files
author
Taois
committed
feat: 更新drplayer
优化部署方式,完善首页,收藏,历史
1 parent 9db175a commit 18e091c

29 files changed

+8850
-307
lines changed

dashboard/.env.production

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# .env.production
2+
# 生产环境配置
3+
# 子目录部署配置 - 例如部署到 /apps/ 目录
4+
VITE_BASE_PATH=/apps/drplayer/
5+
6+
# 如果部署到根目录,使用以下配置:
7+
# VITE_BASE_PATH=./

dashboard/DEPLOYMENT.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# DrPlayer Dashboard 部署指南
2+
3+
本文档提供了 DrPlayer Dashboard 的完整部署指南,解决了子目录部署和SPA路由刷新的问题。
4+
5+
## 构建配置
6+
7+
### 1. 环境变量配置
8+
9+
在项目根目录创建 `.env.production` 文件:
10+
11+
```bash
12+
# 生产环境配置
13+
NODE_ENV=production
14+
15+
# 如果部署到子目录,设置基础路径
16+
# 例如:部署到 /apps/ 目录下
17+
VITE_BASE_PATH=/apps/
18+
19+
# 如果部署到根目录,使用相对路径
20+
# VITE_BASE_PATH=./
21+
```
22+
23+
### 2. 构建命令
24+
25+
```bash
26+
# 安装依赖
27+
npm install
28+
29+
# 构建生产版本
30+
npm run build
31+
32+
# 构建后的文件在 dist 目录中
33+
```
34+
35+
## 部署配置
36+
37+
### Nginx 配置
38+
39+
#### 1. 根目录部署
40+
41+
如果部署到网站根目录(如 `https://example.com/`):
42+
43+
```nginx
44+
server {
45+
listen 80;
46+
server_name example.com;
47+
root /var/www/drplayer/dist;
48+
index index.html;
49+
50+
# 处理静态资源
51+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
52+
expires 1y;
53+
add_header Cache-Control "public, immutable";
54+
try_files $uri =404;
55+
}
56+
57+
# 处理 SPA 路由
58+
location / {
59+
try_files $uri $uri/ /index.html;
60+
}
61+
62+
# 安全配置
63+
location ~ /\. {
64+
deny all;
65+
}
66+
}
67+
```
68+
69+
#### 2. 子目录部署
70+
71+
如果部署到子目录(如 `https://example.com/apps/`):
72+
73+
```nginx
74+
server {
75+
listen 80;
76+
server_name example.com;
77+
78+
# 子目录配置
79+
location /apps/ {
80+
alias /var/www/drplayer/dist/;
81+
index index.html;
82+
83+
# 处理静态资源
84+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
85+
expires 1y;
86+
add_header Cache-Control "public, immutable";
87+
try_files $uri =404;
88+
}
89+
90+
# 处理 SPA 路由 - 关键配置
91+
try_files $uri $uri/ /apps/index.html;
92+
}
93+
94+
# 安全配置
95+
location ~ /\. {
96+
deny all;
97+
}
98+
}
99+
```
100+
101+
#### 3. 使用 location 块的高级配置
102+
103+
```nginx
104+
server {
105+
listen 80;
106+
server_name example.com;
107+
108+
location /apps {
109+
alias /var/www/drplayer/dist;
110+
111+
# 重写规则处理子目录
112+
location ~ ^/apps/(.*)$ {
113+
try_files /$1 /$1/ /index.html;
114+
}
115+
116+
# 静态资源缓存
117+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
118+
expires 1y;
119+
add_header Cache-Control "public, immutable";
120+
}
121+
}
122+
}
123+
```
124+
125+
### Apache 配置
126+
127+
如果使用 Apache 服务器,在 `dist` 目录创建 `.htaccess` 文件:
128+
129+
```apache
130+
# 根目录部署
131+
RewriteEngine On
132+
RewriteBase /
133+
134+
# 处理静态资源
135+
RewriteCond %{REQUEST_FILENAME} !-f
136+
RewriteCond %{REQUEST_FILENAME} !-d
137+
RewriteRule . /index.html [L]
138+
139+
# 子目录部署(例如 /apps/)
140+
# RewriteEngine On
141+
# RewriteBase /apps/
142+
# RewriteCond %{REQUEST_FILENAME} !-f
143+
# RewriteCond %{REQUEST_FILENAME} !-d
144+
# RewriteRule . /apps/index.html [L]
145+
```
146+
147+
## 部署步骤
148+
149+
### 1. 准备构建
150+
151+
```bash
152+
# 1. 设置环境变量(根据部署目录)
153+
echo "VITE_BASE_PATH=/apps/" > .env.production
154+
155+
# 2. 构建项目
156+
npm run build
157+
```
158+
159+
### 2. 上传文件
160+
161+
```bash
162+
# 将 dist 目录内容上传到服务器
163+
scp -r dist/* user@server:/var/www/drplayer/dist/
164+
```
165+
166+
### 3. 配置服务器
167+
168+
```bash
169+
# 1. 配置 nginx
170+
sudo nano /etc/nginx/sites-available/drplayer
171+
sudo ln -s /etc/nginx/sites-available/drplayer /etc/nginx/sites-enabled/
172+
sudo nginx -t
173+
sudo systemctl reload nginx
174+
175+
# 2. 设置文件权限
176+
sudo chown -R www-data:www-data /var/www/drplayer/
177+
sudo chmod -R 755 /var/www/drplayer/
178+
```
179+
180+
## 常见问题解决
181+
182+
### 1. 资源加载 404
183+
184+
**问题**:部署到子目录后,CSS/JS 文件加载失败
185+
186+
**解决**
187+
- 确保 `.env.production` 中设置了正确的 `VITE_BASE_PATH`
188+
- 检查 nginx 配置中的 `alias` 路径是否正确
189+
190+
### 2. 路由刷新 404
191+
192+
**问题**:直接访问路由地址或刷新页面时出现 404
193+
194+
**解决**
195+
- 确保 nginx 配置了正确的 `try_files` 规则
196+
- 检查 `try_files` 中的 fallback 路径是否正确
197+
198+
### 3. 子目录路由问题
199+
200+
**问题**:子目录部署时路由跳转不正确
201+
202+
**解决**
203+
- 确保 Vue Router 的 base 路径配置正确
204+
- 检查环境变量 `VITE_BASE_PATH` 是否正确设置
205+
206+
## 验证部署
207+
208+
部署完成后,验证以下功能:
209+
210+
1. **静态资源加载**:检查浏览器开发者工具,确保所有 CSS/JS 文件正常加载
211+
2. **路由导航**:点击菜单项,确保路由跳转正常
212+
3. **页面刷新**:在任意页面刷新,确保不出现 404 错误
213+
4. **直接访问**:直接在地址栏输入路由地址,确保能正常访问
214+
215+
## 性能优化建议
216+
217+
1. **启用 Gzip 压缩**
218+
2. **设置静态资源缓存**
219+
3. **使用 CDN 加速**
220+
4. **启用 HTTP/2**
221+
222+
```nginx
223+
# Gzip 压缩
224+
gzip on;
225+
gzip_vary on;
226+
gzip_min_length 1024;
227+
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
228+
229+
# HTTP/2
230+
listen 443 ssl http2;
231+
```

0 commit comments

Comments
 (0)