@@ -7,21 +7,14 @@ import path from 'path';
77export default defineConfig ( ( { mode } ) => {
88 const env = loadEnv ( mode , process . cwd ( ) , '' ) ;
99
10- // https://github.com/vitejs/vite/issues/3105#issuecomment-939703781
11- const htmlPlugin = ( ) => ( {
12- name : 'html-transform' ,
13- transformIndexHtml ( html : string ) {
14- return html . replace ( / # ( .* ?) # / g, ( _ , p1 ) => env [ p1 ] ) ;
15- } ,
16- } ) ;
17-
1810 const packagesDir = path . resolve ( __dirname , '..' ) ;
1911
2012 let port = Number . parseInt ( env . PORT , 10 ) ;
2113 if ( Number . isNaN ( port ) || port <= 0 ) {
2214 port = 4020 ;
2315 }
2416
17+ const baseURL = new URL ( env . BASE_URL , `http://localhost:${ port } /` ) ;
2518 // These are paths which should be proxied to the core server
2619 // https://vitejs.dev/config/server-options.html#server-proxy
2720 const proxy = {
@@ -42,11 +35,9 @@ export default defineConfig(({ mode }) => {
4235 // Vite does not have a "any unknown fallback to proxy" like CRA
4336 // It is possible to add one with a custom middleware though if this list grows
4437 if ( env . VITE_PROXY_URL ) {
45- [
46- path . resolve ( env . BASE_URL , env . VITE_CORE_API_URL ) ,
47- path . resolve ( env . BASE_URL , env . VITE_MODULE_PLUGINS_URL ) ,
48- ] . forEach ( p => {
49- proxy [ p ] = {
38+ [ env . VITE_CORE_API_URL , env . VITE_MODULE_PLUGINS_URL ] . forEach ( p => {
39+ const route = new URL ( p , baseURL ) . pathname ;
40+ proxy [ route ] = {
5041 target : env . VITE_PROXY_URL ,
5142 changeOrigin : true ,
5243 } ;
@@ -116,6 +107,6 @@ export default defineConfig(({ mode }) => {
116107 } ,
117108 } ,
118109 } ,
119- plugins : [ htmlPlugin ( ) , react ( ) ] ,
110+ plugins : [ react ( ) ] ,
120111 } ;
121112} ) ;
0 commit comments