kevisual-center/vite.config.ts
2025-01-06 10:44:25 +08:00

87 lines
2.2 KiB
TypeScript

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer';
import path from 'path';
import nesting from 'tailwindcss/nesting';
const isDev = process.env.NODE_ENV === 'development';
const isKV = process.env.VITE_USE_KV === 'true';
const unamiPlugin = {
name: 'html-transform',
transformIndexHtml(html: string) {
return html.replace(
'</head>',
`<script defer src="https://umami.xiongxiao.me/script.js" data-website-id="aeea5ee5-df79-4e78-8c0d-a9f26db23695"></script></head>`,
);
},
};
const plugins = [];
if (!isDev) {
plugins.push(unamiPlugin);
}
let proxy = {};
if (isKV) {
proxy = {
'/api': {
target: 'https://envision.xiongxiao.me',
changeOrigin: true,
rewrite: (path: any) => path.replace(/^\/api/, '/api'),
},
'/api/router': {
target: 'wss://envision.xiongxiao.me',
changeOrigin: true,
ws: true,
rewriteWsOrigin: true,
rewrite: (path: any) => path.replace(/^\/api/, '/api'),
},
'/resources': {
target: 'https://envision.xiongxiao.me',
changeOrigin: true,
rewrite: (path: any) => path.replace(/^\/resources/, '/resources'),
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), ...plugins],
css: {
postcss: {
// @ts-ignore
plugins: [nesting, tailwindcss, autoprefixer],
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
define: {
DEV_SERVER: JSON.stringify(process.env.NODE_ENV === 'development'),
},
server: {
port: 6010,
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://localhost:4002',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/api'),
},
'/api/router': {
target: 'ws://localhost:4002',
changeOrigin: true,
ws: true,
rewriteWsOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/api'),
},
'/resources': {
target: 'https://envision.xiongxiao.me',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/resources/, '/resources'),
},
...proxy,
},
},
});