import { UserConfigExport, defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { resolve } from 'path' import svgr from 'vite-plugin-svgr' import autoCompress from './src/vite-plugins/autoCompress' const commonConfig: UserConfigExport = { plugins: [ react(), svgr({ exportAsDefault: false, include: '**/*.svg' }) ], resolve: { alias: { '@': resolve(__dirname, 'src') }, extensions: ['.tsx', '.ts', '.js', '.json'] }, base: '/' } export default defineConfig(({ command }) => { if (command === 'serve') { commonConfig.server = { proxy: { '/lyq': { target: 'http://120.46.202.213:9000', changeOrigin: true, rewrite(path) { return path.replace(/\/lyq/, '') } } } } return commonConfig } else { const arr = [autoCompress()] commonConfig.plugins.push(...arr) commonConfig.build = { chunkSizeWarningLimit: 1024 * 2 } return commonConfig } })