Files
aichat/vite.config.ts
T
2026-11-05 10:46:36 +08:00

66 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import pkg from "./package.json" with { type: "json" };
// 注意:页面跑在 5173,one-api 在 127.0.0.1:3100(SSH 隧道)—— 两者跨源。
// 必须靠这个 proxy 把 /v1 转过去,让页面请求**同源相对路径**,否则带
// Authorization 头会触发 OPTIONS 预检,one-api 未必放行。
// Phase 2 改为 /Api/aiChat 后,这里只需再加一条同源转发。
export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [ElementPlusResolver()],
dts: false, // 不生成 components.d.ts,项目里 EP 组件都是显式 import 的
}),
],
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
host: '0.0.0.0',
port: 5173,
proxy: {
'/v1': {
target: 'http://127.0.0.1:3100',
changeOrigin: true,
},
},
},
build: {
chunkSizeWarningLimit: 2000,
rolldownOptions: {
output: {
minify: {
compress: {
// dropConsole: true,
// dropDebugger: true,
}
}
}
},
rollupOptions: {
output: {
entryFileNames: "js/[name].[hash].js",
chunkFileNames: "js/[name].[hash].js",
assetFileNames: (assetInfo: any) => {
const info = assetInfo.name.split(".");
let extType = info[info.length - 1];
if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetInfo.name)) extType = "media";
else if (/\.(png|jpe?g|gif|svg)(\?.*)?$/i.test(assetInfo.name)) extType = "img";
else if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(assetInfo.name)) extType = "fonts";
return `${extType}/[name].[hash].[ext]`;
},
},
},
},
})