@@ -8,11 +8,10 @@ import { vitePlugin as remix } from "@remix-run/dev";
8
8
9
9
export default defineConfig ( ( { mode } ) => {
10
10
const {
11
- VITE_BACKEND_HOST = "127.0.0.1:3000" ,
12
- VITE_USE_TLS = "false" ,
13
- VITE_FRONTEND_PORT = "3001" ,
14
- VITE_INSECURE_SKIP_VERIFY = "false" ,
15
- VITE_WATCH_USE_POLLING = "false" ,
11
+ VITE_BACKEND_HOST = "127.0.0.1:3000" ,
12
+ VITE_USE_TLS = "false" ,
13
+ VITE_FRONTEND_PORT = "3001" ,
14
+ VITE_INSECURE_SKIP_VERIFY = "false" ,
16
15
} = loadEnv ( mode , process . cwd ( ) ) ;
17
16
18
17
const USE_TLS = VITE_USE_TLS === "true" ;
@@ -23,6 +22,35 @@ export default defineConfig(({ mode }) => {
23
22
const API_URL = `${ PROTOCOL } ://${ VITE_BACKEND_HOST } /` ;
24
23
const WS_URL = `${ WS_PROTOCOL } ://${ VITE_BACKEND_HOST } /` ;
25
24
const FE_PORT = Number . parseInt ( VITE_FRONTEND_PORT , 10 ) ;
25
+
26
+ /**
27
+ * This script is used to unpack the client directory from the frontend build directory.
28
+ * Remix SPA mode builds the client directory into the build directory. This function
29
+ * moves the contents of the client directory to the build directory and then removes the
30
+ * client directory.
31
+ *
32
+ * This script is used in the buildEnd function of the Vite config.
33
+ */
34
+ const unpackClientDirectory = async ( ) => {
35
+ const fs = await import ( "fs" ) ;
36
+ const path = await import ( "path" ) ;
37
+
38
+ const buildDir = path . resolve ( __dirname , "build" ) ;
39
+ const clientDir = path . resolve ( buildDir , "client" ) ;
40
+
41
+ const files = await fs . promises . readdir ( clientDir ) ;
42
+ await Promise . all (
43
+ files . map ( ( file ) =>
44
+ fs . promises . rename (
45
+ path . resolve ( clientDir , file ) ,
46
+ path . resolve ( buildDir , file ) ,
47
+ ) ,
48
+ ) ,
49
+ ) ;
50
+
51
+ await fs . promises . rmdir ( clientDir ) ;
52
+ } ;
53
+
26
54
return {
27
55
plugins : [
28
56
! process . env . VITEST &&
@@ -33,6 +61,7 @@ export default defineConfig(({ mode }) => {
33
61
v3_throwAbortReason : true ,
34
62
} ,
35
63
appDirectory : "src" ,
64
+ buildEnd : unpackClientDirectory ,
36
65
ssr : false ,
37
66
} ) ,
38
67
viteTsconfigPaths ( ) ,
@@ -67,5 +96,5 @@ export default defineConfig(({ mode }) => {
67
96
include : [ "src/**/*.{ts,tsx}" ] ,
68
97
} ,
69
98
} ,
70
- }
99
+ } ;
71
100
} ) ;
0 commit comments