mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-28 05:42:51 +00:00
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
|
import type { ProxyOptions } from 'vite'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
import DefineOptions from 'unplugin-vue-define-options/vite'
|
|
import path from 'path'
|
|
import { createHtmlPlugin } from 'vite-plugin-html'
|
|
|
|
// import vueDevTools from 'vite-plugin-vue-devtools'
|
|
const envDir = './env'
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
const ENV = loadEnv(mode, envDir)
|
|
console.log(ENV)
|
|
const prefix = process.env.VITE_DYNAMIC_PREFIX || ENV.VITE_BASE_PATH
|
|
const proxyConf: Record<string, string | ProxyOptions> = {}
|
|
proxyConf['/api'] = {
|
|
// target: 'http://43.166.1.146:8080',
|
|
target: 'http://127.0.0.1:8080',
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
|
}
|
|
proxyConf['/oss'] = {
|
|
target: 'http://127.0.0.1:8080',
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
|
}
|
|
proxyConf['/chat/api'] = {
|
|
target: 'http://127.0.0.1:8080',
|
|
changeOrigin: true,
|
|
}
|
|
proxyConf['/doc'] = {
|
|
target: 'http://127.0.0.1:8080',
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
|
}
|
|
proxyConf['/schema'] = {
|
|
target: 'http://127.0.0.1:8080',
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
|
}
|
|
proxyConf['/static'] = {
|
|
target: 'http://127.0.0.1:8080',
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
|
}
|
|
return {
|
|
preflight: false,
|
|
lintOnSave: false,
|
|
base: prefix,
|
|
envDir: envDir,
|
|
plugins: [vue(), vueJsx(), DefineOptions(), createHtmlPlugin({ template: ENV.VITE_ENTRY })],
|
|
server: {
|
|
cors: true,
|
|
host: '0.0.0.0',
|
|
port: Number(ENV.VITE_APP_PORT),
|
|
strictPort: true,
|
|
proxy: proxyConf,
|
|
},
|
|
build: {
|
|
outDir: `dist${ENV.VITE_BASE_PATH}`,
|
|
rollupOptions: {
|
|
input: path.resolve(__dirname, ENV.VITE_ENTRY),
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
}
|
|
})
|