-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.extension.config.ts
More file actions
65 lines (60 loc) · 1.83 KB
/
vite.extension.config.ts
File metadata and controls
65 lines (60 loc) · 1.83 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
import { fileURLToPath, URL } from "node:url";
import react from "@vitejs/plugin-react";
import { defineConfig, loadEnv } from "vite";
function normalizeBaseUrl(value: string | undefined) {
const normalized = value?.trim().replace(/\/+$/g, "");
return normalized || null;
}
export default defineConfig(({ mode }) => {
const repoRoot = fileURLToPath(new URL("./", import.meta.url));
const panelRoot = fileURLToPath(
new URL("./src/extension/panel", import.meta.url)
);
const env = loadEnv(mode, repoRoot, "");
const extensionApiBaseUrl =
normalizeBaseUrl(env.VITE_TWITCH_EXTENSION_API_BASE_URL) ??
normalizeBaseUrl(env.APP_URL);
if (!extensionApiBaseUrl) {
throw new Error(
"build:extension:panel requires VITE_TWITCH_EXTENSION_API_BASE_URL or APP_URL."
);
}
// Force the hosted panel artifact to call the real app origin instead of
// falling back to the Twitch CDN origin at runtime.
return {
root: panelRoot,
envDir: repoRoot,
publicDir: fileURLToPath(new URL("./public", import.meta.url)),
base: "./",
define: {
"import.meta.env.VITE_TWITCH_EXTENSION_API_BASE_URL":
JSON.stringify(extensionApiBaseUrl),
},
resolve: {
alias: {
"~": fileURLToPath(new URL("./src", import.meta.url)),
},
},
plugins: [react()],
build: {
outDir: fileURLToPath(
new URL("./dist/twitch-extension/panel", import.meta.url)
),
emptyOutDir: true,
rollupOptions: {
output: {
manualChunks(id) {
if (
id.includes("node_modules/react/") ||
id.includes("node_modules/react-dom/") ||
id.includes("node_modules/scheduler/")
) {
return "react-vendor";
}
return undefined;
},
},
},
},
};
});