feat: handle VITE_PUBLIC_URL

This commit is contained in:
amhsirak
2024-12-03 23:52:55 +05:30
parent 064318ea92
commit bf80c41e19

View File

@@ -1,11 +1,20 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
import dotenv from 'dotenv';
dotenv.config();
export default defineConfig(() => { export default defineConfig(() => {
const publicUrl = process.env.VITE_PUBLIC_URL || 'http://localhost:5173';
return { return {
define: { define: {
'import.meta.env.VITE_BACKEND_URL': JSON.stringify(process.env.VITE_BACKEND_URL), '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: { build: {
outDir: 'build', outDir: 'build',
manifest: true, manifest: true,