Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
67 lines (64 loc) · 2.02 KB
/
Copy pathvite.config.ts
File metadata and controls
67 lines (64 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { defineConfig, type Plugin } from "vite";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
const here = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(here, "..");
/** Mirror the production Vercel rewrites during local dev and `vite preview`. */
function friendlyPlayRoutes(): Plugin {
const rewrite = (url: string | undefined): string | undefined => {
if (!url) return url;
const queryStart = url.indexOf("?");
const pathname = queryStart === -1 ? url : url.slice(0, queryStart);
const query = queryStart === -1 ? "" : url.slice(queryStart);
if (pathname === "/play" || /^\/play\/[^/]+\/?$/.test(pathname)) {
return `/play.html${query}`;
}
return url;
};
const install = (middlewares: { use: (handler: (
req: { url?: string },
res: unknown,
next: () => void,
) => void) => void }): void => {
middlewares.use((req, _res, next) => {
req.url = rewrite(req.url);
next();
});
};
return {
name: "posecode-friendly-play-routes",
configureServer(server) {
install(server.middlewares);
},
configurePreviewServer(server) {
install(server.middlewares);
},
};
}
export default defineConfig({
root: here,
plugins: [friendlyPlayRoutes()],
resolve: {
alias: {
"posecode-parser": resolve(repoRoot, "packages/posecode-parser/src/index.ts"),
"posecode-render": resolve(repoRoot, "packages/posecode-render/src/index.ts"),
"posecode-share": resolve(repoRoot, "packages/posecode-share/src/index.ts"),
},
dedupe: ["three"],
},
build: {
rollupOptions: {
input: {
// Build files behind the public `/`, `/play[/movement]`, and
// `/for-products` routes.
main: resolve(here, "index.html"),
play: resolve(here, "play.html"),
forProducts: resolve(here, "for-products.html"),
},
},
},
server: {
// Allow importing .posecode examples and llm-authoring.md from spec/.
fs: { allow: [repoRoot] },
},
});