✨ feat: Update Vite configuration to load environment variables for improved API proxy setup
This commit is contained in:
parent
8d514dfd8f
commit
d36a2c902b
@ -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,33 +24,37 @@ function versionLockPlugin(): Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
base: "./",
|
const env = loadEnv(mode, process.cwd(), "");
|
||||||
plugins: [
|
|
||||||
devtools({ eventBusConfig: { port: 42_070 } }),
|
return {
|
||||||
tanstackRouter({
|
base: "./",
|
||||||
target: "react",
|
plugins: [
|
||||||
autoCodeSplitting: true,
|
devtools({ eventBusConfig: { port: 42_070 } }),
|
||||||
}),
|
tanstackRouter({
|
||||||
viteReact(),
|
target: "react",
|
||||||
tailwindcss(),
|
autoCodeSplitting: true,
|
||||||
versionLockPlugin(),
|
}),
|
||||||
],
|
viteReact(),
|
||||||
resolve: {
|
tailwindcss(),
|
||||||
alias: {
|
versionLockPlugin(),
|
||||||
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
],
|
||||||
},
|
resolve: {
|
||||||
},
|
alias: {
|
||||||
server: {
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
||||||
proxy: {
|
|
||||||
"/api": {
|
|
||||||
target: import.meta.env.VITE_API_BASE_URL || "https://api.ppanel.dev",
|
|
||||||
changeOrigin: true,
|
|
||||||
secure: false,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
server: {
|
||||||
build: {
|
proxy: {
|
||||||
assetsDir: "static",
|
"/api": {
|
||||||
},
|
target: env.VITE_API_BASE_URL || "https://api.ppanel.dev",
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
assetsDir: "static",
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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,33 +24,37 @@ function versionLockPlugin(): Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
base: "./",
|
const env = loadEnv(mode, process.cwd(), "");
|
||||||
plugins: [
|
|
||||||
devtools({ eventBusConfig: { port: 42_069 } }),
|
return {
|
||||||
tanstackRouter({
|
base: "./",
|
||||||
target: "react",
|
plugins: [
|
||||||
autoCodeSplitting: true,
|
devtools({ eventBusConfig: { port: 42_069 } }),
|
||||||
}),
|
tanstackRouter({
|
||||||
viteReact(),
|
target: "react",
|
||||||
tailwindcss(),
|
autoCodeSplitting: true,
|
||||||
versionLockPlugin(),
|
}),
|
||||||
],
|
viteReact(),
|
||||||
resolve: {
|
tailwindcss(),
|
||||||
alias: {
|
versionLockPlugin(),
|
||||||
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
],
|
||||||
},
|
resolve: {
|
||||||
},
|
alias: {
|
||||||
server: {
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
||||||
proxy: {
|
|
||||||
"/api": {
|
|
||||||
target: import.meta.env.VITE_API_BASE_URL || "https://api.ppanel.dev",
|
|
||||||
changeOrigin: true,
|
|
||||||
secure: false,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
server: {
|
||||||
build: {
|
proxy: {
|
||||||
assetsDir: "static",
|
"/api": {
|
||||||
},
|
target: env.VITE_API_BASE_URL || "https://api.ppanel.dev",
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
assetsDir: "static",
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user