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 ## 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` 1. `main.tsx`
```diff ```diff
createRoot(document.getElementById("root")!).render( # <---- 检查必须是 #root createRoot(document.getElementById("root")!).render( # <---- 检查必须是 #root
<StrictMode> <StrictMode>
- <BrowserRouter> - <BrowserRouter>
+ <BrowserRouter basename={import.meta.env.BASE_URL}> + <BrowserRouter basename="alisurvey"> # <---- 需要和项目文件夹名一致
<App /> <App />
<Toaster /> <Toaster />
</BrowserRouter> </BrowserRouter>
@@ -73,10 +73,15 @@ createRoot(document.getElementById("root")!).render( # <---- 检查必须是 #r
2. `vite.config.ts` 2. `vite.config.ts`
```diff ```diff
export default defineConfig({ -export default defineConfig({
plugins: getPlugins() - plugins: getPlugins()
+ base: '/alisurvey', # <---- 需要和项目文件夹名一致 -});
}); +export default defineConfig(({ command }) => ({
+ plugins: getPlugins(),
+ base: command === 'build'
+ ? '/wp-content/products/react-apps/alisurvey/' # <---- 存放到 wordpress 的路径,末尾需要 /
+ : '/alisurvey' # <---- 本地用,需要和项目文件夹名一致
+}));
``` ```
## 2. 修改 pnpm 为 npm [可选] ## 2. 修改 pnpm 为 npm [可选]