UnisKB/ui/vite.config.ts

75 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-04-14 12:11:23 +00:00
import { fileURLToPath, URL } from 'node:url'
2025-04-16 11:10:00 +00:00
import type { ProxyOptions } from 'vite'
import { defineConfig, loadEnv } from 'vite'
2025-04-14 12:11:23 +00:00
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
2025-04-16 11:10:00 +00:00
import DefineOptions from 'unplugin-vue-define-options/vite'
2025-06-13 08:17:02 +00:00
import path from 'path'
import { createHtmlPlugin } from 'vite-plugin-html'
2025-04-16 11:10:00 +00:00
// import vueDevTools from 'vite-plugin-vue-devtools'
const envDir = './env'
2025-04-14 12:11:23 +00:00
// https://vite.dev/config/
2025-04-16 11:10:00 +00:00
export default defineConfig(({ mode }) => {
const ENV = loadEnv(mode, envDir)
2025-06-17 03:58:35 +00:00
console.log(ENV)
2025-04-16 11:10:00 +00:00
const prefix = process.env.VITE_DYNAMIC_PREFIX || ENV.VITE_BASE_PATH
const proxyConf: Record<string, string | ProxyOptions> = {}
proxyConf['/api'] = {
2025-06-24 06:49:09 +00:00
// target: 'http://47.92.195.88:8080',
target: 'http://127.0.0.1:8080',
2025-04-16 11:10:00 +00:00
changeOrigin: true,
2025-06-13 08:17:02 +00:00
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
2025-06-06 04:31:30 +00:00
}
2025-06-13 08:17:02 +00:00
proxyConf['/oss'] = {
2025-06-06 04:31:30 +00:00
target: 'http://127.0.0.1:8080',
changeOrigin: true,
2025-06-16 04:08:09 +00:00
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
}
2025-06-17 03:58:35 +00:00
proxyConf['/chat/api'] = {
2025-06-16 04:08:09 +00:00
target: 'http://127.0.0.1:8080',
changeOrigin: true,
2025-04-16 11:10:00 +00:00
}
proxyConf['/doc'] = {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
2025-06-13 08:17:02 +00:00
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
2025-04-16 11:10:00 +00:00
}
proxyConf['/schema'] = {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
}
2025-04-16 11:10:00 +00:00
proxyConf['/static'] = {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
2025-06-13 08:17:02 +00:00
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
2025-04-16 11:10:00 +00:00
}
return {
preflight: false,
lintOnSave: false,
base: prefix,
envDir: envDir,
2025-06-13 08:48:55 +00:00
plugins: [vue(), vueJsx(), DefineOptions(), createHtmlPlugin({ template: ENV.VITE_ENTRY })],
2025-04-16 11:10:00 +00:00
server: {
cors: true,
host: '0.0.0.0',
port: Number(ENV.VITE_APP_PORT),
strictPort: true,
proxy: proxyConf,
},
build: {
2025-06-13 08:17:02 +00:00
outDir: `dist${ENV.VITE_BASE_PATH}`,
rollupOptions: {
2025-06-13 08:48:55 +00:00
input: path.resolve(__dirname, ENV.VITE_ENTRY),
2025-06-13 08:17:02 +00:00
},
2025-04-16 11:10:00 +00:00
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
2025-04-14 12:11:23 +00:00
},
2025-04-16 11:10:00 +00:00
}
2025-04-14 12:11:23 +00:00
})