Skip to content

Commit e9ee930

Browse files
committed
feat: use local assets in dev server if possible
1 parent 278177e commit e9ee930

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
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 & 19 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,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/
4144
export 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(/^\/api\/mira/, "/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(/^\/api\/mira/, "/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

Comments
 (0)