fix(build): vite部署问题,部署后有缓存取到旧的chunk文件
This commit is contained in:
1 parent
09deada712
commit
57652ae581
7 files changed
+62
-108
No files matched your search
@@ -55,6 +55,19 @@ location /api/ {
|
||||
}
|
||||
```
|
||||
|
||||
同时为静态与 `index.html` 设置了缓存策略,避免部署后浏览器/网关缓存旧版 `index.html`,引用部署时已删除的旧 hash 产物,导致登录后懒加载 chunk 404(报 `Failed to fetch dynamically imported module`):
|
||||
|
||||
```nginx
|
||||
# Vite 构建产物(带 hash、内容寻址):可长期 immutable 缓存,文件名一变即失效
|
||||
location /assets/ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
}
|
||||
# index.html 必须始终重新校验,避免引用旧 hash
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
```
|
||||
|
||||
#### 5.2.3 自动化部署脚本 (`scripts/deploy_compose.sh`)
|
||||
当前标准部署入口(Jenkins 与服务器手工均使用此脚本):
|
||||
1. **环境选择**: 参数 `dev` / `test` / `prod`,对应 `.env.dev`、`.env.test`、`.env.prod` 与 `.env.shared`。
|
||||
|
||||
Reference in new issue
Block a user