Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

vite.config.ts

123 lines4.1 KB

1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3​
4import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts";
5import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
6​
7const repoEnv = loadRepoEnv();
8​
9// The main process is bundled the same way the server CLI is: every JS
10// dependency is inlined and only packages Node must load from disk stay
11// external. The packaged app then installs just those externals, instead of a
12// full production install of apps/desktop's dependency tree next to a server
13// bundle that already carries its own copy of the same libraries.
14const isMainProcessExternal = (id: string) =>
15 id === "electron" || id.startsWith("electron/") || isDesktopRuntimeExternalDependency(id);
16const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1";
17const publicConfigDefine = {
18 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
19 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
20 ),
21};
22​
23export default defineConfig({
24 run: {
25 tasks: {
26 build: {
27 command:
28 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack",
29 dependsOn: ["t3#build"],
30 cache: false,
31 },
32 dev: {
33 command:
34 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && cross-env T3CODE_DESKTOP_DEV=1 vp pack --watch",
35 dependsOn: ["t3#build"],
36 cache: false,
37 },
38 "dev:bundle": {
39 command:
40 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack --watch",
41 cache: false,
42 },
43 "dev:electron": {
44 command: "node scripts/dev-electron.mjs",
45 dependsOn: ["t3#build"],
46 cache: false,
47 },
48 },
49 },
50 pack: [
51 {
52 format: "cjs",
53 outDir: "dist-electron",
54 dts: false,
55 sourcemap: true,
56 outExtensions: () => ({ js: ".cjs" }),
57 define: publicConfigDefine,
58 entry: [
59 "src/main.ts",
60 "src/electron/WindowsForegroundFocusWorker.ts",
61 "src/snapShot/GlobalShiftShortcutWorker.ts",
62 "src/snapShot/RegionSnapShotWorker.ts",
63 "src/snapShot/SnapShotAccessibilityWorker.ts",
64 ],
65 clean: true,
66 deps: {
67 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
68 neverBundle: isMainProcessExternal,
69 onlyBundle: false,
70 },
71 ...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
72 },
73 {
74 format: "cjs",
75 outDir: "dist-electron",
76 dts: false,
77 sourcemap: true,
78 outExtensions: () => ({ js: ".cjs" }),
79 define: publicConfigDefine,
80 entry: ["src/preload.ts"],
81 deps: {
82 // Sandboxed Electron preloads cannot reliably resolve package imports
83 // from inside the packaged ASAR. Bundle Clerk's preload bridge into the
84 // preload artifact instead of leaving a runtime require() behind.
85 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
86 },
87 },
88 {
89 format: "cjs",
90 outDir: "dist-electron",
91 dts: false,
92 sourcemap: true,
93 outExtensions: () => ({ js: ".cjs" }),
94 entry: ["src/preview-pick-preload.ts"],
95 deps: {
96 alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
97 },
98 },
99 {
100 format: "cjs",
101 outDir: "dist-electron",
102 dts: false,
103 sourcemap: true,
104 outExtensions: () => ({ js: ".cjs" }),
105 entry: ["src/preview-pip-preload.ts"],
106 },
107 {
108 // Sandboxed preloads must be self-contained, without shared runtime chunks.
109 format: "cjs",
110 outDir: "dist-electron",
111 dts: false,
112 sourcemap: true,
113 outExtensions: () => ({ js: ".cjs" }),
114 entry: ["src/mac-permission-preload.ts"],
115 },
116 ],
117 test: {
118 // The Windows lane runs workspace suites concurrently; filesystem-heavy
119 // desktop integration tests can exceed Vitest's 5 second default there.
120 testTimeout: 15_000,
121 setupFiles: ["../../packages/shared/src/testing/longTempDir.ts"],
122 },
123});