writekit/frontends/owner-tools/vite.config.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import UnoCSS from 'unocss/vite'
import { resolve } from 'path'
export default defineConfig(({ command }) => ({
plugins: [
// Only use UnoCSS plugin in dev mode for HMR
...(command === 'serve' ? [UnoCSS()] : []),
...(command === 'build' ? [react()] : []),
],
base: command === 'serve' ? '/@owner-tools' : '/',
esbuild: {
jsxInject: `import React from 'react'`
},
resolve: {
alias: command === 'serve' ? {
// In dev mode, alias the generated file to virtual:uno.css
'./uno-generated.css': 'virtual:uno.css',
} : {},
},
...(command === 'serve' && {
server: {
host: true,
port: 5174,
strictPort: true,
allowedHosts: true,
hmr: {
clientPort: 80,
path: '/@owner-tools'
},
proxy: {
'/api/studio': {
target: 'http://app:8080',
changeOrigin: true
}
}
}
}),
build: {
lib: {
entry: resolve(__dirname, 'src/main.tsx'),
name: 'OwnerTools',
formats: ['iife'],
fileName: () => 'owner-tools.js'
},
outDir: '../../internal/tenant/assets/js',
emptyOutDir: false,
}
}))