import {defineConfig, loadEnv, type Plugin} from 'vite'
import react from '@vitejs/plugin-react'
function themeContract(origin: string): Plugin {
const base = origin.replace(/\/+$/, '')
return {
name: 'go-bananas-contract',
transformIndexHtml(html) {
if (!base) return html
const tags = [
``,
``,
].join('\n ')
return html.replace('', ` ${tags}\n `)
},
}
}
export default defineConfig(({mode}) => {
const env = loadEnv(mode, '.', '')
const themeOrigin = env.VITE_THEME_BASE_URL || ''
return {
plugins: [react(), themeContract(themeOrigin)],
build: {
outDir: '../dist',
emptyOutDir: true,
},
server: {
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
},
'/health': {
target: 'http://localhost:8080',
changeOrigin: true,
},
},
},
}
})