import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path from 'path'; // https://vite.dev/config/ export default defineConfig({ server: { hmr: true, host: '::', allowedHosts: [ '.mymoyu.top', // 注意是点开头,不是星号 'localhost', '127.0.0.1', '192.168.1.4' ], proxy: { '/api': { target: 'http://127.0.0.1:8002', changeOrigin: true, bypass: (req) => { if (req.headers.accept?.includes('text/html')) { return req.url; } }, }, '/ws': { target: 'ws://127.0.0.1:8002', ws: true, rewrite: (path) => path.replace(/^\/ws/, ''), }, '/media/': { target: 'http://127.0.0.1:8002', changeOrigin: true, }, '/user': { target: 'http://127.0.0.1:8002', changeOrigin: true, bypass: (req) => { if (req.headers.accept?.includes('text/html')) { return req.url; } }, }, }, }, plugins: [react()], resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, })