50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { defineConfig, loadEnv, type ProxyOptions } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import path from 'node:path';
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), '');
|
|
const target = env.VITE_PROXY_TARGET || 'https://dev-vibemake-api.robotquan.com';
|
|
const proxy: Record<string, ProxyOptions> = {
|
|
'/admin-api': {
|
|
target,
|
|
changeOrigin: true,
|
|
secure: true,
|
|
// 后端 CORS 只放行白名单来源,浏览器带的 Origin(localhost) 会被拒绝返回 403。
|
|
// 代理请求本就同源,去掉 Origin 让后端按普通请求处理。
|
|
configure: (p) => {
|
|
p.on('proxyReq', (req) => {
|
|
req.removeHeader('origin');
|
|
req.removeHeader('referer');
|
|
});
|
|
},
|
|
},
|
|
};
|
|
return {
|
|
plugins: [react()],
|
|
resolve: { alias: { '@': path.resolve(__dirname, 'src') } },
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 8091,
|
|
strictPort: true,
|
|
// 开发环境统一代理 /admin-api 到后端,避免跨域
|
|
proxy,
|
|
},
|
|
build: {
|
|
chunkSizeWarningLimit: 1500,
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
react: ['react', 'react-dom', 'react-router-dom'],
|
|
antd: ['antd', '@ant-design/icons', 'dayjs'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
preview: {
|
|
port: 4173,
|
|
proxy,
|
|
},
|
|
};
|
|
});
|