Skip to content

Commit 8a357a0

Browse files
Use Local Assets in Development If Possible [AARD-2008] (#1227)
Co-authored-by: Zach Rutman <92497727+rutmanz@users.noreply.github.com> Co-authored-by: Brandon Pacewic <92102436+BrandonPacewic@users.noreply.github.com>
2 parents 278177e + 61088c6 commit 8a357a0

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

fission/tsconfig.node.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"module": "ESNext",
66
"moduleResolution": "bundler",
77
"allowSyntheticDefaultImports": true,
8-
"strict": true
8+
"strict": true,
9+
"target": "ESNext"
910
},
1011
"include": ["vite.config.ts"]
1112
}

fission/vite.config.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import react from "@vitejs/plugin-react-swc"
44
import basicSsl from "@vitejs/plugin-basic-ssl"
55
import glsl from "vite-plugin-glsl"
66
import { loadEnv, ProxyOptions } from "vite"
7-
7+
import fs from "node:fs/promises"
88
const basePath = "/fission/"
99
const serverPort = 3000
1010
const dockerServerPort = 80
@@ -37,34 +37,44 @@ 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+
4042
// https://vitejs.dev/config/
41-
export default defineConfig(({ mode, }) => {
43+
export default defineConfig(({ mode }) => {
4244
process.env = {...process.env, ...loadEnv(mode, process.cwd())};
43-
const useLocalAssets = mode === "test" || process.env.DEV
45+
46+
const useLocalAssets = localAssetsExist && (mode === "test" || process.env.NODE_ENV=="development")
47+
48+
if (!localAssetsExist && (mode === "test" || process.env.NODE_ENV=="development")) {
49+
console.warn("Can't find local assets, do you need to run `npm run assetpack`?")
50+
}
51+
52+
console.log(`Using ${useLocalAssets?"local":"remote"} mirabuf assets`)
53+
4454
const proxies: Record<string, ProxyOptions> = {}
4555
proxies["/api/mira"] = useLocalAssets
4656
? {
47-
target: `http://localhost:${mode === "test" ? 3001 : serverPort}`,
48-
changeOrigin: true,
49-
secure: false,
50-
rewrite: path => path.replace(/^\/api\/mira/, "/Downloadables/Mira").replace("robots", "Robots").replace("fields", "Fields"),
51-
}
57+
target: `http://localhost:${mode === "test" ? 3001 : serverPort}`,
58+
changeOrigin: true,
59+
secure: false,
60+
rewrite: path => path.replace(/^\/api\/mira/, "/Downloadables/Mira").replace("robots", "Robots").replace("fields", "Fields"),
61+
}
5262
: {
53-
target: `https://synthesis.autodesk.com/`,
54-
changeOrigin: true,
55-
secure: true,
56-
}
63+
target: `https://synthesis.autodesk.com/`,
64+
changeOrigin: true,
65+
secure: true,
66+
}
5767
proxies["/api/aps"] = useLocalAPS
5868
? {
59-
target: `http://localhost:${dockerServerPort}/`,
60-
changeOrigin: true,
61-
secure: false,
62-
}
69+
target: `http://localhost:${dockerServerPort}/`,
70+
changeOrigin: true,
71+
secure: false,
72+
}
6373
: {
64-
target: `https://synthesis.autodesk.com/`,
65-
changeOrigin: true,
66-
secure: true,
67-
}
74+
target: `https://synthesis.autodesk.com/`,
75+
changeOrigin: true,
76+
secure: true,
77+
}
6878

6979
return {
7080
plugins: plugins,

0 commit comments

Comments
 (0)