You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

import { resolve } from 'node:path'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
const webRoot = fileURLToPath(new URL('.', import.meta.url))
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const isAdminDeploy = mode === 'admin'
return {
base: isAdminDeploy ? '/admin/' : '/',
build: {
outDir: isAdminDeploy
? resolve(webRoot, '../slake-school-service/public/admin')
: 'dist',
emptyOutDir: true,
},
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
port: 5173,
// 天地图 Key 域名白名单为 slake.ali251.langye.net 时,本地可用 hosts 指向 127.0.0.1 后访问该域名
host: true,
allowedHosts: ['slake.ali251.langye.net', 'localhost', '127.0.0.1'],
proxy: {
// 与 Laravel `RouteServiceProvider` 中 `prefix('api')` 对齐,本地联调 slake-school-service
'/api': {
target: env.VITE_PROXY_TARGET || 'http://127.0.0.1:8000',
changeOrigin: true,
// 论文爬虫含 arXiv 多轮请求,避免代理 10s 默认超时
timeout: 300_000,
},
// 封面/宣传图等外链为 /storage/* 时,避免打到 Vite 5173 而 404
'/storage': {
target: env.VITE_PROXY_TARGET || 'http://127.0.0.1:8000',
changeOrigin: true,
},
},
},
}
})