From bf80c41e19efe7f23fad91ed7ea42b88a8887103 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Tue, 3 Dec 2024 23:52:55 +0530 Subject: [PATCH] feat: handle VITE_PUBLIC_URL --- vite.config.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vite.config.js b/vite.config.js index 59f495a1..9ca574eb 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,11 +1,20 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; +import dotenv from 'dotenv'; +dotenv.config(); export default defineConfig(() => { + const publicUrl = process.env.VITE_PUBLIC_URL || 'http://localhost:5173'; + return { define: { 'import.meta.env.VITE_BACKEND_URL': JSON.stringify(process.env.VITE_BACKEND_URL), + 'import.meta.env.VITE_PUBLIC_URL': JSON.stringify(publicUrl), }, + server: { + host: new URL(publicUrl).hostname, + port: parseInt(new URL(publicUrl).port), + }, build: { outDir: 'build', manifest: true,