From 86f6caa7149823b1e540e99caa8051cb94680f03 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Fri, 24 Jan 2025 21:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E7=BB=9F=E8=AE=A1&?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- napcat.webui/.env | 1 + napcat.webui/index.html | 2 -- napcat.webui/vite-env.d.ts | 9 +++++ napcat.webui/vite.config.ts | 71 ++++++++++++++++++++----------------- 4 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 napcat.webui/.env create mode 100644 napcat.webui/vite-env.d.ts diff --git a/napcat.webui/.env b/napcat.webui/.env new file mode 100644 index 00000000..e5012111 --- /dev/null +++ b/napcat.webui/.env @@ -0,0 +1 @@ +VITE_DEBUG_BACKEND_URL="http://127.0.0.1:6099" diff --git a/napcat.webui/index.html b/napcat.webui/index.html index 06d8f283..995dfcb2 100644 --- a/napcat.webui/index.html +++ b/napcat.webui/index.html @@ -13,8 +13,6 @@ content="viewport-fit=cover, width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" /> - diff --git a/napcat.webui/vite-env.d.ts b/napcat.webui/vite-env.d.ts new file mode 100644 index 00000000..c7826ffe --- /dev/null +++ b/napcat.webui/vite-env.d.ts @@ -0,0 +1,9 @@ +/// + +interface ImportMetaEnv { + readonly VITE_DEBUG_BACKEND_URL: string +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} diff --git a/napcat.webui/vite.config.ts b/napcat.webui/vite.config.ts index 1ff24f9f..f36c3dbc 100644 --- a/napcat.webui/vite.config.ts +++ b/napcat.webui/vite.config.ts @@ -1,45 +1,50 @@ import react from '@vitejs/plugin-react' import path from 'node:path' -import { defineConfig, normalizePath } from 'vite' +import { defineConfig, loadEnv, normalizePath } from 'vite' import { viteStaticCopy } from 'vite-plugin-static-copy' import tsconfigPaths from 'vite-tsconfig-paths' const monacoEditorPath = normalizePath( path.resolve(__dirname, 'node_modules/monaco-editor/min/vs') ) + // https://vitejs.dev/config/ -export default defineConfig({ - plugins: [ - react(), - tsconfigPaths(), - viteStaticCopy({ - targets: [ - { - src: monacoEditorPath, - dest: 'monaco-editor/min' - } - ] - }) - ], - base: '/webui/', - server: { - proxy: { - '/api': 'http://192.168.30.10:6099' - // '/api': 'http://127.0.0.1:6099' - } - }, - build: { - assetsInlineLimit: 0, - rollupOptions: { - output: { - manualChunks: { - 'monaco-editor': ['monaco-editor'], - 'react-dom': ['react-dom'], - 'react-router-dom': ['react-router-dom'], - 'react-hook-form': ['react-hook-form'], - 'react-icons': ['react-icons'], - 'react-hot-toast': ['react-hot-toast'], - qface: ['qface'] +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd()) + const backendDebugUrl = env.VITE_DEBUG_BACKEND_URL + console.log('backendDebugUrl', backendDebugUrl) + return { + plugins: [ + react(), + tsconfigPaths(), + viteStaticCopy({ + targets: [ + { + src: monacoEditorPath, + dest: 'monaco-editor/min' + } + ] + }) + ], + base: '/webui/', + server: { + proxy: { + '/api': backendDebugUrl + } + }, + build: { + assetsInlineLimit: 0, + rollupOptions: { + output: { + manualChunks: { + 'monaco-editor': ['monaco-editor'], + 'react-dom': ['react-dom'], + 'react-router-dom': ['react-router-dom'], + 'react-hook-form': ['react-hook-form'], + 'react-icons': ['react-icons'], + 'react-hot-toast': ['react-hot-toast'], + qface: ['qface'] + } } } }