From d36a2c902b7943441282278009c5e5210d30c746 Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Mon, 29 Dec 2025 07:16:13 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Update=20Vite=20configurati?= =?UTF-8?q?on=20to=20load=20environment=20variables=20for=20improved=20API?= =?UTF-8?q?=20proxy=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/vite.config.ts | 60 +++++++++++++++++++++------------------ apps/user/vite.config.ts | 60 +++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/apps/admin/vite.config.ts b/apps/admin/vite.config.ts index 97a1593..a03c3f5 100644 --- a/apps/admin/vite.config.ts +++ b/apps/admin/vite.config.ts @@ -4,7 +4,7 @@ import tailwindcss from "@tailwindcss/vite"; import { devtools } from "@tanstack/devtools-vite"; import { tanstackRouter } from "@tanstack/router-plugin/vite"; 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 function versionLockPlugin(): Plugin { @@ -24,33 +24,37 @@ function versionLockPlugin(): Plugin { } // https://vitejs.dev/config/ -export default defineConfig({ - base: "./", - plugins: [ - devtools({ eventBusConfig: { port: 42_070 } }), - tanstackRouter({ - target: "react", - autoCodeSplitting: true, - }), - viteReact(), - tailwindcss(), - versionLockPlugin(), - ], - resolve: { - alias: { - "@": fileURLToPath(new URL("./src", import.meta.url)), - }, - }, - server: { - proxy: { - "/api": { - target: import.meta.env.VITE_API_BASE_URL || "https://api.ppanel.dev", - changeOrigin: true, - secure: false, +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ""); + + return { + base: "./", + plugins: [ + devtools({ eventBusConfig: { port: 42_070 } }), + tanstackRouter({ + target: "react", + autoCodeSplitting: true, + }), + viteReact(), + tailwindcss(), + versionLockPlugin(), + ], + resolve: { + alias: { + "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, - }, - build: { - assetsDir: "static", - }, + server: { + proxy: { + "/api": { + target: env.VITE_API_BASE_URL || "https://api.ppanel.dev", + changeOrigin: true, + secure: false, + }, + }, + }, + build: { + assetsDir: "static", + }, + }; }); diff --git a/apps/user/vite.config.ts b/apps/user/vite.config.ts index 9d0c236..43771e8 100644 --- a/apps/user/vite.config.ts +++ b/apps/user/vite.config.ts @@ -4,7 +4,7 @@ import tailwindcss from "@tailwindcss/vite"; import { devtools } from "@tanstack/devtools-vite"; import { tanstackRouter } from "@tanstack/router-plugin/vite"; 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 function versionLockPlugin(): Plugin { @@ -24,33 +24,37 @@ function versionLockPlugin(): Plugin { } // https://vitejs.dev/config/ -export default defineConfig({ - base: "./", - plugins: [ - devtools({ eventBusConfig: { port: 42_069 } }), - tanstackRouter({ - target: "react", - autoCodeSplitting: true, - }), - viteReact(), - tailwindcss(), - versionLockPlugin(), - ], - resolve: { - alias: { - "@": fileURLToPath(new URL("./src", import.meta.url)), - }, - }, - server: { - proxy: { - "/api": { - target: import.meta.env.VITE_API_BASE_URL || "https://api.ppanel.dev", - changeOrigin: true, - secure: false, +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ""); + + return { + base: "./", + plugins: [ + devtools({ eventBusConfig: { port: 42_069 } }), + tanstackRouter({ + target: "react", + autoCodeSplitting: true, + }), + viteReact(), + tailwindcss(), + versionLockPlugin(), + ], + resolve: { + alias: { + "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, - }, - build: { - assetsDir: "static", - }, + server: { + proxy: { + "/api": { + target: env.VITE_API_BASE_URL || "https://api.ppanel.dev", + changeOrigin: true, + secure: false, + }, + }, + }, + build: { + assetsDir: "static", + }, + }; });