Files

55 lines
1.6 KiB
TypeScript

import type { DefineConfig } from '@vben/vite-config/src/typing';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { defineConfig } from '@vben/vite-config';
import { apiTypeGeneratorPlugin } from './plugins/api-type-generator';
const config: DefineConfig = async () => {
const proxyTarget =
process.env.VITE_DEV_PROXY_TARGET || 'http://localhost:8008';
return {
application: {},
vite: {
plugins: [
// 生成API类型文件
apiTypeGeneratorPlugin({
apiRoot: fileURLToPath(new URL('src/api', import.meta.url)),
}) as any,
],
server: {
allowedHosts: ['www.test.com'],
proxy: {
// 拉整个API文件
'/api.json': {
changeOrigin: true,
target: proxyTarget,
// target: 'http://iotlcm.example.com:8008', // 生产环境
},
// 正常API代理
'/api': {
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
target: `${proxyTarget}/api/v1`,
// target: 'http://iotlcm.example.com:8008/api/v1', // 生产环境
ws: true,
},
// 文件上传代理
'/upload': {
changeOrigin: true,
rewrite: (path) => path.replace(/^\/upload/, ''),
target: `${proxyTarget}/upload`,
// target: 'http://iotlcm.example.com:8008/upload', // 生产环境
ws: true,
},
},
},
},
};
};
export default defineConfig(config) as import('vite').UserConfigExport;