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'] + } } } }