feat: Update Vite configuration to load environment variables for improved API proxy setup

This commit is contained in:
web@ppanel 2025-12-29 07:16:13 +00:00
parent 8d514dfd8f
commit d36a2c902b
2 changed files with 64 additions and 56 deletions

View File

@ -4,7 +4,7 @@ import tailwindcss from "@tailwindcss/vite";
import { devtools } from "@tanstack/devtools-vite"; import { devtools } from "@tanstack/devtools-vite";
import { tanstackRouter } from "@tanstack/router-plugin/vite"; import { tanstackRouter } from "@tanstack/router-plugin/vite";
import viteReact from "@vitejs/plugin-react"; import viteReact from "@vitejs/plugin-react";
import { defineConfig, type Plugin } from "vite"; import { defineConfig, loadEnv, type Plugin } from "vite";
// Plugin to generate version.lock file after build // Plugin to generate version.lock file after build
function versionLockPlugin(): Plugin { function versionLockPlugin(): Plugin {
@ -24,7 +24,10 @@ function versionLockPlugin(): Plugin {
} }
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
base: "./", base: "./",
plugins: [ plugins: [
devtools({ eventBusConfig: { port: 42_070 } }), devtools({ eventBusConfig: { port: 42_070 } }),
@ -44,7 +47,7 @@ export default defineConfig({
server: { server: {
proxy: { proxy: {
"/api": { "/api": {
target: import.meta.env.VITE_API_BASE_URL || "https://api.ppanel.dev", target: env.VITE_API_BASE_URL || "https://api.ppanel.dev",
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
}, },
@ -53,4 +56,5 @@ export default defineConfig({
build: { build: {
assetsDir: "static", assetsDir: "static",
}, },
};
}); });

View File

@ -4,7 +4,7 @@ import tailwindcss from "@tailwindcss/vite";
import { devtools } from "@tanstack/devtools-vite"; import { devtools } from "@tanstack/devtools-vite";
import { tanstackRouter } from "@tanstack/router-plugin/vite"; import { tanstackRouter } from "@tanstack/router-plugin/vite";
import viteReact from "@vitejs/plugin-react"; import viteReact from "@vitejs/plugin-react";
import { defineConfig, type Plugin } from "vite"; import { defineConfig, loadEnv, type Plugin } from "vite";
// Plugin to generate version.lock file after build // Plugin to generate version.lock file after build
function versionLockPlugin(): Plugin { function versionLockPlugin(): Plugin {
@ -24,7 +24,10 @@ function versionLockPlugin(): Plugin {
} }
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
base: "./", base: "./",
plugins: [ plugins: [
devtools({ eventBusConfig: { port: 42_069 } }), devtools({ eventBusConfig: { port: 42_069 } }),
@ -44,7 +47,7 @@ export default defineConfig({
server: { server: {
proxy: { proxy: {
"/api": { "/api": {
target: import.meta.env.VITE_API_BASE_URL || "https://api.ppanel.dev", target: env.VITE_API_BASE_URL || "https://api.ppanel.dev",
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
}, },
@ -53,4 +56,5 @@ export default defineConfig({
build: { build: {
assetsDir: "static", assetsDir: "static",
}, },
};
}); });