Update README.md

This commit is contained in:
2025-09-26 10:18:16 +00:00
parent 8dd1e3c34f
commit f46da4da00

View File

@@ -58,14 +58,14 @@ include_toc: true
## 1. 修改 baseUrl
> 参考这个 commit https://git.alicorns.co.jp/xuejiahao/website-products/commit/98dac11ece9c262b24376a3ff1227731b0ff96fd
> 参考这个 commit https://git.alicorns.co.jp/xuejiahao/website-products/commit/8dd1e3c34f4633f8fae7f3ade0513b6c6c1f1822
1. `main.tsx`
```diff
createRoot(document.getElementById("root")!).render( # <---- 检查必须是 #root
<StrictMode>
- <BrowserRouter>
+ <BrowserRouter basename={import.meta.env.BASE_URL}>
+ <BrowserRouter basename="alisurvey"> # <---- 需要和项目文件夹名一致
<App />
<Toaster />
</BrowserRouter>
@@ -73,10 +73,15 @@ createRoot(document.getElementById("root")!).render( # <---- 检查必须是 #r
2. `vite.config.ts`
```diff
export default defineConfig({
plugins: getPlugins()
+ base: '/alisurvey', # <---- 需要和项目文件夹名一致
});
-export default defineConfig({
- plugins: getPlugins()
-});
+export default defineConfig(({ command }) => ({
+ plugins: getPlugins(),
+ base: command === 'build'
+ ? '/wp-content/products/react-apps/alisurvey/' # <---- 存放到 wordpress 的路径,末尾需要 /
+ : '/alisurvey' # <---- 本地用,需要和项目文件夹名一致
+}));
```
## 2. 修改 pnpm 为 npm [可选]