Files
Enterprise-Knowledge-Base/frontend/vite.config.ts
T
wizardchen 3475af1707 feat(frontend): configure API proxy target for development environment
Updated the Vite configuration to allow dynamic setting of the API proxy target based on environment variables. The default target is now configurable via VITE_DEV_PROXY_TARGET or FRONTEND_BACKEND_URL, enhancing flexibility for different development setups. Additionally, the development script logs the current API proxy target for better visibility during startup.
2026-05-20 21:00:16 +08:00

66 lines
1.7 KiB
TypeScript

import { fileURLToPath, URL } from 'node:url'
import { resolve, dirname } from 'node:path'
import { existsSync } from 'node:fs'
import { createRequire } from 'node:module'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
const __dirname = dirname(fileURLToPath(import.meta.url))
const require = createRequire(import.meta.url)
const pkg = require('./package.json') as { version?: string }
const FRONTEND_VERSION = pkg.version ?? 'unknown'
const DEV_PROXY_TARGET =
process.env.VITE_DEV_PROXY_TARGET ||
process.env.FRONTEND_BACKEND_URL ||
'http://localhost:8080'
function resolveVueOfficePptxEntry(): string {
try {
const pkgDir = dirname(require.resolve('@vue-office/pptx/package.json'))
const candidates = [
resolve(pkgDir, 'lib/v3/index.js'),
resolve(pkgDir, 'lib/index.js'),
resolve(pkgDir, 'lib/v3/vue-office-pptx.mjs'),
]
const matched = candidates.find((candidate) => existsSync(candidate))
return matched ?? '@vue-office/pptx'
} catch {
return '@vue-office/pptx'
}
}
export default defineConfig({
define: {
__FRONTEND_VERSION__: JSON.stringify(FRONTEND_VERSION),
},
plugins: [
vue(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@vue-office/pptx': resolveVueOfficePptxEntry(),
},
},
server: {
port: 5173,
host: true,
// 代理配置,用于开发环境
proxy: {
'/api': {
target: DEV_PROXY_TARGET,
changeOrigin: true,
secure: false,
},
'/files': {
target: DEV_PROXY_TARGET,
changeOrigin: true,
secure: false,
}
}
}
})