@@ -2,25 +2,29 @@ import { reactRouter } from "@react-router/dev/vite";
22import tailwindcss from "@tailwindcss/vite" ;
33import mdx from "fumadocs-mdx/vite" ;
44import path from "node:path" ;
5- import { env } from "node:process" ;
6- import { defineConfig } from "vite" ;
5+ import { defineConfig , loadEnv } from "vite" ;
76import devtoolsJson from "vite-plugin-devtools-json" ;
87
98import * as MdxConfig from "./source.config" ;
109
11- const isDev = env . NODE_ENV === "development" ;
12- export default defineConfig ( {
13- base : isDev ? "/" : `${ env . VITE_APP_API_URL } /` ,
14- plugins : [ mdx ( MdxConfig ) , tailwindcss ( ) , reactRouter ( ) , devtoolsJson ( ) ] ,
15- resolve : {
16- tsconfigPaths : true ,
17- alias : {
18- "@" : path . resolve ( __dirname , "./app" ) ,
19- ...( ! isDev
20- ? {
21- "react-dom/server" : "react-dom/server.node" ,
22- }
23- : { } ) ,
10+ export default defineConfig ( ( { command, mode } ) => {
11+ const env = loadEnv ( mode , process . cwd ( ) , "VITE_APP_" ) ;
12+ const isDev = command === "serve" ;
13+ const contextPath = env . VITE_APP_API_URL ?. trim ( ) ?? "" ;
14+
15+ return {
16+ base : isDev || ! contextPath ? "/" : `${ contextPath } /` ,
17+ plugins : [ mdx ( MdxConfig ) , tailwindcss ( ) , reactRouter ( ) , devtoolsJson ( ) ] ,
18+ resolve : {
19+ tsconfigPaths : true ,
20+ alias : {
21+ "@" : path . resolve ( __dirname , "./app" ) ,
22+ ...( ! isDev
23+ ? {
24+ "react-dom/server" : "react-dom/server.node" ,
25+ }
26+ : { } ) ,
27+ } ,
2428 } ,
25- } ,
29+ } ;
2630} ) ;
0 commit comments