Read WEB_PORT / PORT (or API_PROXY_TARGET) from the monorepo root .env via loadEnv, so the dev server can run alongside other local projects when 5173 and 8080 are already taken. Defaults are unchanged (5173 -> localhost:8080). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
eb36b81dc9
commit
434de547ce
+33
-27
@@ -1,36 +1,42 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
plugins: [react()],
|
// Read the monorepo root .env (all keys, not just VITE_*) so ports stay configurable there.
|
||||||
// VITE_* vars live in the monorepo root .env alongside the API's config.
|
const env = { ...loadEnv(mode, path.resolve(__dirname, '../..'), ''), ...process.env };
|
||||||
envDir: path.resolve(__dirname, '../..'),
|
|
||||||
resolve: {
|
return {
|
||||||
alias: {
|
plugins: [react()],
|
||||||
'@': path.resolve(__dirname, 'src'),
|
// VITE_* vars live in the monorepo root .env alongside the API's config.
|
||||||
},
|
envDir: path.resolve(__dirname, '../..'),
|
||||||
},
|
resolve: {
|
||||||
server: {
|
alias: {
|
||||||
port: 5173,
|
'@': path.resolve(__dirname, 'src'),
|
||||||
proxy: {
|
|
||||||
'/api': {
|
|
||||||
target: 'http://localhost:8080',
|
|
||||||
changeOrigin: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
server: {
|
||||||
build: {
|
// Ports are overridable so this app can run alongside other local projects.
|
||||||
outDir: 'dist',
|
port: Number(env.WEB_PORT ?? 5173),
|
||||||
sourcemap: false,
|
proxy: {
|
||||||
rollupOptions: {
|
'/api': {
|
||||||
output: {
|
target: env.API_PROXY_TARGET ?? `http://localhost:${env.PORT ?? 8080}`,
|
||||||
manualChunks: {
|
changeOrigin: true,
|
||||||
'vendor-react': ['react', 'react-dom', 'react-router-dom'],
|
|
||||||
'vendor-ui': ['framer-motion', 'lucide-react'],
|
|
||||||
'vendor-charts': ['recharts'],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
build: {
|
||||||
|
outDir: 'dist',
|
||||||
|
sourcemap: false,
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
manualChunks: {
|
||||||
|
'vendor-react': ['react', 'react-dom', 'react-router-dom'],
|
||||||
|
'vendor-ui': ['framer-motion', 'lucide-react'],
|
||||||
|
'vendor-charts': ['recharts'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user