fix(build): vite部署问题,部署后有缓存取到旧的chunk文件

This commit is contained in:
sophie committed 2026-08-28 11:34:37 +08:00
1 parent 09deada712
commit 57652ae581
7 files changed
+62 -108

No files matched your search

+13
View File
@@ -14,6 +14,19 @@ server {
try_files $uri $uri/ /index.html;
}
# Vite 构建产物(/assets/ 下带 hash 文件):内容寻址,文件名一变即换新缓存,可放心长期 immutable 缓存。
location /assets/ {
root /usr/share/nginx/html;
add_header Cache-Control "public, max-age=31536000, immutable";
}
# index.html 必须始终重新校验(no-cache):避免浏览器/网关缓存旧版 HTML,引用部署后已删除的旧 hash 产物,
# 导致登录后懒加载 chunk 404,报 "Failed to fetch dynamically imported module"。
location = /index.html {
root /usr/share/nginx/html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# API 代理到后端
location /api/ {
# 通过 Docker 内置 DNS 动态解析后端服务,避免后端容器重建后