@@ -10,60 +10,64 @@ import react from '@vitejs/plugin-react-swc';
1010import { defineConfig } from 'vite' ;
1111import viteCompression from 'vite-plugin-compression' ;
1212
13- const apiPort = parseNumber ( process . env . API_DEV_SERVER_PORT ) ;
14- const webPort = parseNumber ( process . env . WEB_DEV_SERVER_PORT ) ;
13+ export default defineConfig ( async ( { command } ) => {
14+ const apiPort = parseNumber ( process . env . API_DEV_SERVER_PORT ) ;
15+ const webPort = parseNumber ( process . env . WEB_DEV_SERVER_PORT ) ;
1516
16- if ( Number . isNaN ( apiPort ) ) {
17- throw new Error ( `Expected API_DEV_SERVER_PORT to be number, got ${ process . env . API_DEV_SERVER_PORT } ` ) ;
18- } else if ( Number . isNaN ( webPort ) ) {
19- throw new Error ( `Expected WEB_DEV_SERVER_PORT to be number, got ${ process . env . WEB_DEV_SERVER_PORT } ` ) ;
20- }
17+ if ( command === 'serve' ) {
18+ if ( Number . isNaN ( apiPort ) ) {
19+ throw new Error ( `Expected API_DEV_SERVER_PORT to be number, got ${ process . env . API_DEV_SERVER_PORT } ` ) ;
20+ } else if ( Number . isNaN ( webPort ) ) {
21+ throw new Error ( `Expected WEB_DEV_SERVER_PORT to be number, got ${ process . env . WEB_DEV_SERVER_PORT } ` ) ;
22+ }
23+ }
2124
22- export default defineConfig ( {
23- build : {
24- chunkSizeWarningLimit : 1000 ,
25- emptyOutDir : false ,
26- sourcemap : true ,
27- target : 'es2022'
28- } ,
29- define : {
30- __RELEASE__ : JSON . stringify ( await getReleaseInfo ( ) )
31- } ,
32- optimizeDeps : {
33- esbuildOptions : {
25+ return {
26+ build : {
27+ chunkSizeWarningLimit : 1000 ,
28+ emptyOutDir : false ,
29+ sourcemap : true ,
3430 target : 'es2022'
3531 } ,
36- include : [ 'react/*' , 'react-dom/*' ]
37- } ,
38- plugins : [
39- tanstackRouter ( {
40- autoCodeSplitting : true ,
41- generatedRouteTree : './src/route-tree.ts' ,
42- target : 'react'
43- } ) ,
44- react ( ) ,
45- viteCompression ( ) ,
46- importMetaEnv . vite ( {
47- example : path . resolve ( import . meta. dirname , '.env.public' )
48- } ) as any ,
49- runtime ( ) ,
50- tailwindcss ( )
51- ] ,
52- resolve : {
53- alias : {
54- '@' : path . resolve ( import . meta. dirname , 'src' )
55- }
56- } ,
57- server : {
58- port : webPort ,
59- proxy : {
60- '/api/' : {
61- rewrite : ( path ) => path . replace ( / ^ \/ a p i / , '' ) ,
62- target : {
63- host : 'localhost' ,
64- port : apiPort
32+ define : {
33+ __RELEASE__ : JSON . stringify ( await getReleaseInfo ( ) )
34+ } ,
35+ optimizeDeps : {
36+ esbuildOptions : {
37+ target : 'es2022'
38+ } ,
39+ include : [ 'react/*' , 'react-dom/*' ]
40+ } ,
41+ plugins : [
42+ tanstackRouter ( {
43+ autoCodeSplitting : true ,
44+ generatedRouteTree : './src/route-tree.ts' ,
45+ target : 'react'
46+ } ) ,
47+ react ( ) ,
48+ viteCompression ( ) ,
49+ importMetaEnv . vite ( {
50+ example : path . resolve ( import . meta. dirname , '.env.public' )
51+ } ) as any ,
52+ runtime ( ) ,
53+ tailwindcss ( )
54+ ] ,
55+ resolve : {
56+ alias : {
57+ '@' : path . resolve ( import . meta. dirname , 'src' )
58+ }
59+ } ,
60+ server : {
61+ port : webPort ,
62+ proxy : {
63+ '/api/' : {
64+ rewrite : ( path : string ) => path . replace ( / ^ \/ a p i / , '' ) ,
65+ target : {
66+ host : 'localhost' ,
67+ port : apiPort
68+ }
6569 }
6670 }
6771 }
68- }
72+ } ;
6973} ) ;
0 commit comments