Sfoglia il codice sorgente

feat: 更新README.md

f-dev 1 settimana fa
parent
commit
e35199ca1b
1 ha cambiato i file con 39 aggiunte e 5 eliminazioni
  1. 39 5
      README.md

+ 39 - 5
README.md

@@ -149,12 +149,46 @@ pnpm dev
 
 ## 部署
 
-- 构建产物在 **`dist/client/`**(framework 模式产物结构,非旧的 `dist/`),将对应环境的构建结果部署到静态服务器或 CDN 即可。`ssr:false` 为纯静态预渲染,**无需常驻 Node 服务**,对 CDN 加速零影响。
+两种渲染模式的产物目录与 nginx 配置**不同**,按实际构建的模式选择对应配置。多环境通过 `build:dev` / `build:test` / `build:prod` 与对应 `.env.*` 区分。
+
+### SSG 模式(默认)
+
+- 产物在 **`dist/client/`**(framework 模式产物结构)。`ssr:false` 为纯静态预渲染,**无需常驻 Node 服务**,对 CDN 加速零影响。
 - 预渲染路径在 `react-router.config.ts` 的 `prerender()` 中配置;未预渲染的路径由 SPA fallback(`dist/client/index.html`)承载。
-- nginx 需配置 SPA fallback 兜底(详见 [SSG 架构文档](./docs/SSG.md)):
+- nginx 需先尝试命中预渲染静态页,再回落 SPA fallback(详见 [SSG 架构文档](./docs/SSG.md)):
+  ```nginx
+  server {
+      root /var/www/home-web/dist/client;
+
+      location / {
+          # 依次尝试:精确文件 → 目录 index(命中预渲染页) → flat 后缀 → 回落 SPA fallback
+          try_files $uri $uri/ $uri.html /index.html;
+      }
+
+      # 带 hash 的静态资源长缓存
+      location /assets/ {
+          expires 1y;
+          add_header Cache-Control "public, immutable";
+      }
+  }
+  ```
+
+### CSR 模式
+
+- 产物在 **`dist/`**,仅有一个空壳 `index.html`,无预渲染文件,即标准单页应用部署。
+- nginx 只需最基础的 SPA fallback(无需 `$uri/`、`$uri.html`,产物里没有对应文件):
   ```nginx
-  location / {
-      try_files $uri $uri/ $uri.html /index.html;
+  server {
+      root /var/www/home-web/dist;
+
+      location / {
+          try_files $uri /index.html;
+      }
+
+      # 带 hash 的静态资源长缓存
+      location /assets/ {
+          expires 1y;
+          add_header Cache-Control "public, immutable";
+      }
   }
   ```
-- 多环境通过 `build:dev` / `build:test` / `build:prod` 与对应 `.env.*` 区分。