From ced76bd39aabe6e05a49b7d8de4e7f81e3ba55ef Mon Sep 17 00:00:00 2001 From: dolphin <78075021@qq.com> Date: Fri, 28 Jun 2024 16:39:20 +0800 Subject: [PATCH] feat: vite config --- src/frontend/src/layout/MainLayout.tsx | 6 +- .../ChatAppPage/components/ResouceModal.tsx | 4 +- src/frontend/src/pages/LoginPage/login.tsx | 8 +-- .../pages/SystemPage/components/EditRole.tsx | 4 +- src/frontend/vite.config.ts | 56 +++++++++++++++---- 5 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/frontend/src/layout/MainLayout.tsx b/src/frontend/src/layout/MainLayout.tsx index 3b546dff5..cd9e8b550 100755 --- a/src/frontend/src/layout/MainLayout.tsx +++ b/src/frontend/src/layout/MainLayout.tsx @@ -135,13 +135,13 @@ export default function MainLayout() { {t('menu.models')} } - {/* { - 中英 + {/* 中英 */} + { isMenu('evaluation') && {t('menu.evaluation')} - } */} + } { isAdmin && <> diff --git a/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx b/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx index 83bf338f6..2c2e66efe 100644 --- a/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx +++ b/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx @@ -91,7 +91,7 @@ const ResultPanne = ({ chatId, words, data, onClose, onAdd, children }: { chatId
{/* label */} {/* 中英 */} - {/*
+
{t('chat.filterLabel')}
?
@@ -109,7 +109,7 @@ const ResultPanne = ({ chatId, words, data, onClose, onAdd, children }: { chatId }}>
:
{t('chat.addCustomLabel')}
} -
*/} + {/* files */}

{t('chat.sourceDocumentsLabel')}

diff --git a/src/frontend/src/pages/LoginPage/login.tsx b/src/frontend/src/pages/LoginPage/login.tsx index abe9311b3..bc3665513 100644 --- a/src/frontend/src/pages/LoginPage/login.tsx +++ b/src/frontend/src/pages/LoginPage/login.tsx @@ -178,10 +178,10 @@ export const LoginPage = () => { ) } {/* 中英 */} - - {/* { + disabled={isLoading} onClick={handleLogin} >{t('login.loginButton')} */} + { showLogin ? <>
setShowLogin(false)}>{t('login.noAccountRegister')} @@ -198,7 +198,7 @@ export const LoginPage = () => { className='h-[48px] mt-[32px] dark:bg-button' disabled={isLoading} onClick={handleRegister} >{t('login.registerButton')} - } */} + } {appConfig.hasSSO && }
diff --git a/src/frontend/src/pages/SystemPage/components/EditRole.tsx b/src/frontend/src/pages/SystemPage/components/EditRole.tsx index ca566ffbe..8a3af826d 100644 --- a/src/frontend/src/pages/SystemPage/components/EditRole.tsx +++ b/src/frontend/src/pages/SystemPage/components/EditRole.tsx @@ -200,12 +200,12 @@ export default function EditRole({ id, name, groupId, onChange, onBeforeChange } {/* 中英 */} - {/* + 评测 switchDataChange(MenuType.EVALUATION, 'useMenu', bln)} /> - */} +
diff --git a/src/frontend/vite.config.ts b/src/frontend/vite.config.ts index d369b4e48..edad03d12 100644 --- a/src/frontend/vite.config.ts +++ b/src/frontend/vite.config.ts @@ -1,12 +1,13 @@ import react from "@vitejs/plugin-react-swc"; -import { visualizer } from "rollup-plugin-visualizer"; +import path from "path"; import { defineConfig } from "vite"; +import { createHtmlPlugin } from 'vite-plugin-html'; import { viteStaticCopy } from 'vite-plugin-static-copy'; import svgr from "vite-plugin-svgr"; -const apiRoutes = ["^/api/", "/health"]; -import path from "path"; + // Use environment variable to determine the target. const target = process.env.VITE_PROXY_TARGET || "http://192.168.106.120:3002"; +const apiRoutes = ["^/api/", "/health"]; const proxyTargets = apiRoutes.reduce((proxyObj, route) => { proxyObj[route] = { @@ -16,19 +17,41 @@ const proxyTargets = apiRoutes.reduce((proxyObj, route) => { secure: false, ws: true, }; - // 文件服务地址 - proxyObj['/bisheng'] = { - target: "http://127.0.0.1:50061", - changeOrigin: true, - withCredentials: true, - secure: false - } return proxyObj; }, {}); +// 文件服务地址 +proxyTargets['/bisheng'] = { + target: "http://127.0.0.1:50061", + changeOrigin: true, + withCredentials: true, + secure: false +} +proxyTargets['/custom_base/api'] = { + target, + changeOrigin: true, + withCredentials: true, + secure: false, + rewrite: (path) => { + return path.replace(/^\/custom_base\/api/, '/api'); + }, + configure: (proxy, options) => { + proxy.on('proxyReq', (proxyReq, req, res) => { + console.log('Proxying request to:', proxyReq.path); + }); + } +} + +/** + * 开启子路由访问 + * 开启后一般外层网管匹配【custom】时直接透传转到内层网关 + * 内层网关访问 api或者前端静态资源需要去掉【custom】前缀 +*/ +// const app_env = { BASE_URL: '/custom' } +const app_env = { BASE_URL: '' } export default defineConfig(() => { return { - // base: '/poo', + base: app_env.BASE_URL || '/', build: { // minify: 'esbuild', // 使用 esbuild 进行 Tree Shaking 和压缩 outDir: "build", @@ -51,6 +74,14 @@ export default defineConfig(() => { plugins: [ react(), svgr(), + createHtmlPlugin({ + minify: true, + inject: { + data: { + aceScriptSrc: ``, + }, + }, + }), viteStaticCopy({ targets: [ { @@ -74,6 +105,9 @@ export default defineConfig(() => { // open: true, // }) ], + define: { + __APP_ENV__: JSON.stringify(app_env) + }, server: { host: '0.0.0.0', port: 3001,