-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.ts
More file actions
83 lines (82 loc) · 3.27 KB
/
Copy pathvite.config.ts
File metadata and controls
83 lines (82 loc) · 3.27 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { fileURLToPath } from "node:url";
import { defineConfig, loadEnv, type PluginOption } from "vite";
import react from "@vitejs/plugin-react";
import { worktreePort } from "./scripts/worktree-port.mjs";
import {
parseCommunityAliases,
relayOrigin,
} from "./src/features/communities/destination.ts";
export default defineConfig(async ({ command, mode }) => {
const env = loadEnv(mode, ".", "BUZZ_");
// The development broker is the dev server's default: it runs whenever the
// developer has pinned their public key. Production builds (`pnpm build`,
// `pnpm tauri build`) never load it, regardless of .env.local contents.
const live = command === "serve" && Boolean(env.BUZZ_DEV_VIEWER?.trim());
const aliases = env.BUZZ_COMMUNITY_ALIASES ?? "";
parseCommunityAliases(aliases);
// Public routing configuration only; the viewer pin and credentials stay in Node.
const defaultRelay = env.BUZZ_RELAY_URL?.trim();
const defaultOrigin = defaultRelay ? relayOrigin(defaultRelay) : "";
// Opt-in seed: a viewer with no saved client record on this dev origin starts
// in the default relay's community. The legacy alias is presence-only; an
// explicit dev setting wins (only "1" enables it). Builds never see it.
const openRelay =
live &&
(env.BUZZ_DEV_OPEN_RELAY !== undefined
? env.BUZZ_DEV_OPEN_RELAY === "1"
: env.BUZZ_BUILD_AUTO_CONNECT_DEFAULT_RELAY !== undefined);
if (openRelay && !defaultOrigin)
throw new Error(
"BUZZ_DEV_OPEN_RELAY=1 requires BUZZ_RELAY_URL to name the community to open.",
);
const plugins: PluginOption[] = [react()];
if (command === "serve")
plugins.push(
(await import("./dev/developer-settings.ts")).developerSettingsPlugin(
process.cwd(),
),
);
if (live)
plugins.push(
(await import("./dev/relay-broker.mjs")).relayBrokerPlugin({
authorizedViewer: env.BUZZ_DEV_VIEWER,
relayUrl: defaultRelay,
communityAliases: aliases,
}),
);
const profileReadyToken = process.env.BUZZ_PROFILE_VITE_READY_TOKEN;
if (profileReadyToken)
plugins.push({
name: "buzz-profile-ready",
configureServer(server) {
server.httpServer?.once("listening", () => {
const address = server.httpServer?.address();
if (address && typeof address === "object")
console.log(
`BUZZ_PROFILE_VITE_READY:${profileReadyToken}:${JSON.stringify(address)}`,
);
});
},
});
return {
plugins,
define: {
"import.meta.env.VITE_BUZZ_LIVE": JSON.stringify(live ? "1" : "0"),
"import.meta.env.VITE_BUZZ_NOTIFICATIONS_PAUSED": JSON.stringify(
command === "serve" && env.BUZZ_DEV_NOTIFICATIONS === "0" ? "1" : "0",
),
"import.meta.env.VITE_BUZZ_COMMUNITY_ALIASES": JSON.stringify(aliases),
"import.meta.env.VITE_BUZZ_OPEN_RELAY": JSON.stringify(
openRelay ? defaultOrigin : "",
),
},
clearScreen: false,
server: {
// Derived from this checkout's path, exactly as `just desktop` does, so
// each worktree has its own stable default. The CLI's --port still wins.
port: worktreePort(fileURLToPath(new URL(".", import.meta.url))),
strictPort: false,
watch: { ignored: ["**/src-tauri/**", "**/target/**"] },
},
};
});