From 79e5b45e6b1d41ac735fa2ecbdc81106ec656427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Thu, 5 Nov 2026 20:47:16 +0900 Subject: [PATCH] refactor: update HTML structure and improve deployment instructions - Cleaned up the HTML structure in `index.html` for better readability. - Updated `README.md` to clarify deployment instructions for subdirectory setups. - Removed unused `BASE_URL` declaration from `vite-env.d.ts` and adjusted `AppRoot` to use `import.meta.env.BASE_URL` for improved environment variable handling. --- README.MD | 15 ++++++++++++++- index.html | 4 ---- src/components/AppRoot.tsx | 2 +- src/vite-env.d.ts | 4 ---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.MD b/README.MD index 89dfafc..d5c8a80 100644 --- a/README.MD +++ b/README.MD @@ -92,8 +92,21 @@ docker run -d -p 8080:80 --name um-react um-react 然后访问 `http://localhost:8080` 即可。 +## 部署到子目录 + > [!NOTE] -> 项目不支持运行在子目录下。 +> 官方 Docker 镜像与默认构建产物按站点**根路径**(`/`)部署,不支持部署到子目录下。 + +若要部署到子目录(例如 `https://example.com/um-react/`),你需要重新使用 Vite 进行构建,并指定 `--base` 参数(路径以 `/` 开头、以 `/` 结尾)。 + +以部署到 `https://example.com/um-react/` 为例: + +```sh +pnpm exec vite build --base=/um-react/ +pnpm build:finalize +``` + +部署时,服务器还需把该子目录下的所有前端路由回退到对应的 `index.html`(SPA)。 ## 开发相关 diff --git a/index.html b/index.html index b6751ea..2637967 100644 --- a/index.html +++ b/index.html @@ -9,10 +9,6 @@ - diff --git a/src/components/AppRoot.tsx b/src/components/AppRoot.tsx index 9affca9..a371f3f 100644 --- a/src/components/AppRoot.tsx +++ b/src/components/AppRoot.tsx @@ -30,7 +30,7 @@ function AppBootFallback() { export function AppRoot() { return ( - + }> diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 91ce5dc..02deb07 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -17,7 +17,3 @@ declare module '*&mac-command' { export const commandName: string; export const tarName: string; } - -declare interface Window { - BASE_URL: string; -}