mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
cleaned up vite.config.ts
This commit is contained in:
@@ -1,29 +1,18 @@
|
|||||||
// vite.config.ts
|
|
||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
|
||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
const isProduction = mode === 'production'
|
const isProduction = mode === 'production'
|
||||||
const isDevelopment = mode === 'development'
|
|
||||||
|
|
||||||
const env = loadEnv(mode, process.cwd(), '')
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
|
|
||||||
// 🆕 WICHTIG: Relative Pfade für Production
|
|
||||||
const clientEnv = {
|
|
||||||
NODE_ENV: mode,
|
|
||||||
ENABLE_PRO: env.ENABLE_PRO || 'false',
|
|
||||||
VITE_APP_TITLE: env.APP_TITLE || 'Shift Planning App',
|
|
||||||
VITE_API_URL: isProduction ? '/api' : '/api',
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
|
||||||
server: isDevelopment ? {
|
// Development proxy
|
||||||
|
server: isProduction ? undefined : {
|
||||||
port: 3003,
|
port: 3003,
|
||||||
host: true,
|
host: true,
|
||||||
open: true,
|
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:3002',
|
target: 'http://localhost:3002',
|
||||||
@@ -31,45 +20,54 @@ export default defineConfig(({ mode }) => {
|
|||||||
secure: false,
|
secure: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} : undefined,
|
},
|
||||||
|
|
||||||
|
// Production build optimized for Express serving
|
||||||
build: {
|
build: {
|
||||||
outDir: 'dist',
|
outDir: 'dist',
|
||||||
sourcemap: isDevelopment,
|
sourcemap: false, // Disable in production
|
||||||
base: isProduction ? '/' : '/',
|
minify: 'terser',
|
||||||
|
|
||||||
|
// Bundle optimization
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
|
// Efficient chunking
|
||||||
|
manualChunks: {
|
||||||
|
vendor: ['react', 'react-dom', 'react-router-dom'],
|
||||||
|
utils: ['date-fns']
|
||||||
|
},
|
||||||
|
// Cache-friendly naming
|
||||||
chunkFileNames: 'assets/[name]-[hash].js',
|
chunkFileNames: 'assets/[name]-[hash].js',
|
||||||
entryFileNames: 'assets/[name]-[hash].js',
|
entryFileNames: 'assets/[name]-[hash].js',
|
||||||
assetFileNames: 'assets/[name]-[hash].[ext]',
|
assetFileNames: 'assets/[name]-[hash].[ext]',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
minify: isProduction ? 'terser' : false,
|
|
||||||
terserOptions: isProduction ? {
|
// Performance optimizations
|
||||||
|
terserOptions: {
|
||||||
compress: {
|
compress: {
|
||||||
drop_console: true,
|
drop_console: true,
|
||||||
drop_debugger: true,
|
drop_debugger: true,
|
||||||
pure_funcs: ['console.log', 'console.debug', 'console.info']
|
pure_funcs: ['console.log', 'console.debug']
|
||||||
}
|
}
|
||||||
} : undefined,
|
},
|
||||||
|
|
||||||
|
// Reduce chunking overhead
|
||||||
|
chunkSizeWarningLimit: 800
|
||||||
},
|
},
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, './src'),
|
'@': resolve(__dirname, './src'),
|
||||||
'@/components': resolve(__dirname, './src/components'),
|
// ... other aliases
|
||||||
'@/pages': resolve(__dirname, './src/pages'),
|
|
||||||
'@/contexts': resolve(__dirname, './src/contexts'),
|
|
||||||
'@/models': resolve(__dirname, './src/models'),
|
|
||||||
'@/utils': resolve(__dirname, './src/utils'),
|
|
||||||
'@/services': resolve(__dirname, './src/services'),
|
|
||||||
'@/design': resolve(__dirname, './src/design')
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
define: Object.keys(clientEnv).reduce((acc, key) => {
|
// Environment variables
|
||||||
acc[`import.meta.env.${key}`] = JSON.stringify(clientEnv[key])
|
define: {
|
||||||
return acc
|
'import.meta.env.VITE_API_URL': JSON.stringify(isProduction ? '/api' : '/api'),
|
||||||
}, {} as Record<string, string>)
|
'import.meta.env.ENABLE_PRO': JSON.stringify(env.ENABLE_PRO || 'false'),
|
||||||
|
'import.meta.env.NODE_ENV': JSON.stringify(mode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user