@@ -4,7 +4,7 @@ import react from "@vitejs/plugin-react-swc"
44import basicSsl from "@vitejs/plugin-basic-ssl"
55import glsl from "vite-plugin-glsl"
66import { loadEnv , ProxyOptions } from "vite"
7-
7+ import fs from "node:fs/promises"
88const basePath = "/fission/"
99const serverPort = 3000
1010const dockerServerPort = 80
@@ -37,34 +37,45 @@ if (useSsl) {
3737 plugins . push ( basicSsl ( ) )
3838}
3939
40+ const localAssetsExist = await fs . access ( "./public/Downloadables/Mira" , fs . constants . R_OK ) . then ( ( ) => true ) . catch ( ( ) => false )
41+
42+
4043// https://vitejs.dev/config/
4144export default defineConfig ( ( { mode, } ) => {
4245 process . env = { ...process . env , ...loadEnv ( mode , process . cwd ( ) ) } ;
43- const useLocalAssets = mode === "test" || process . env . DEV
46+
47+ const useLocalAssets = localAssetsExist && ( mode === "test" || process . env . NODE_ENV == "development" )
48+
49+ if ( ! localAssetsExist && ( mode === "test" || process . env . NODE_ENV == "development" ) ) {
50+ console . warn ( "Can't find local assets, do you need to run `npm run assetpack`?" )
51+ }
52+
53+ console . log ( `Using ${ useLocalAssets ?"local" :"remote" } mirabuf assets` )
54+
4455 const proxies : Record < string , ProxyOptions > = { }
4556 proxies [ "/api/mira" ] = useLocalAssets
4657 ? {
47- target : `http://localhost:${ mode === "test" ? 3001 : serverPort } ` ,
48- changeOrigin : true ,
49- secure : false ,
50- rewrite : path => path . replace ( / ^ \/ a p i \/ m i r a / , "/Downloadables/Mira" ) . replace ( "robots" , "Robots" ) . replace ( "fields" , "Fields" ) ,
51- }
58+ target : `http://localhost:${ mode === "test" ? 3001 : serverPort } ` ,
59+ changeOrigin : true ,
60+ secure : false ,
61+ rewrite : path => path . replace ( / ^ \/ a p i \/ m i r a / , "/Downloadables/Mira" ) . replace ( "robots" , "Robots" ) . replace ( "fields" , "Fields" ) ,
62+ }
5263 : {
53- target : `https://synthesis.autodesk.com/` ,
54- changeOrigin : true ,
55- secure : true ,
56- }
64+ target : `https://synthesis.autodesk.com/` ,
65+ changeOrigin : true ,
66+ secure : true ,
67+ }
5768 proxies [ "/api/aps" ] = useLocalAPS
5869 ? {
59- target : `http://localhost:${ dockerServerPort } /` ,
60- changeOrigin : true ,
61- secure : false ,
62- }
70+ target : `http://localhost:${ dockerServerPort } /` ,
71+ changeOrigin : true ,
72+ secure : false ,
73+ }
6374 : {
64- target : `https://synthesis.autodesk.com/` ,
65- changeOrigin : true ,
66- secure : true ,
67- }
75+ target : `https://synthesis.autodesk.com/` ,
76+ changeOrigin : true ,
77+ secure : true ,
78+ }
6879
6980 return {
7081 plugins : plugins ,
0 commit comments