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

vite.config.ts

158 lines5.2 KB

1import "vite-plus/test/config";
2import { defaultInclude, 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 packaged app then installs just those externals, instead of a full
10// production install of apps/desktop's dependency tree next to a server bundle
11// that already carries its own copy of the same libraries.
12const isMainProcessExternal = (id: string) =>
13 id === "electron" || id.startsWith("electron/") || isDesktopRuntimeExternalDependency(id);
14const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1";
15const publicConfigDefine = {
16 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
17 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
18 ),
19};
20​
21export default defineConfig({
22 run: {
23 tasks: {
24 build: {
25 command:
26 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack",
27 dependsOn: ["t3#build"],
28 cache: false,
29 },
30 dev: {
31 command:
32 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && cross-env T3CODE_DESKTOP_DEV=1 vp pack --watch",
33 dependsOn: ["t3#build"],
34 cache: false,
35 },
36 "dev:bundle": {
37 command:
38 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack --watch",
39 cache: false,
40 },
41 "dev:electron": {
42 command: "node scripts/dev-electron.mjs",
43 dependsOn: ["t3#build"],
44 cache: false,
45 },
46 // tsc-rs rewrites the tsbuildinfo it reads, which keeps a task out of the cache.
47 typecheck: {
48 command: "tsc-rs --noEmit",
49 cache: { input: [{ auto: true }, "!*.tsbuildinfo"] },
50 },
51 },
52 },
53 pack: [
54 {
55 format: "cjs",
56 outDir: "dist-electron",
57 dts: false,
58 sourcemap: true,
59 outExtensions: () => ({ js: ".cjs" }),
60 define: publicConfigDefine,
61 outputOptions: { codeSplitting: false },
62 entry: ["src/main.ts"],
63 clean: true,
64 deps: {
65 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
66 neverBundle: isMainProcessExternal,
67 onlyBundle: false,
68 },
69 ...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
70 },
71 {
72 format: "cjs",
73 outDir: "dist-electron",
74 dts: false,
75 sourcemap: true,
76 outExtensions: () => ({ js: ".cjs" }),
77 define: publicConfigDefine,
78 entry: [
79 "src/electron/WindowsForegroundFocusWorker.ts",
80 "src/snapShot/GlobalShiftShortcutWorker.ts",
81 "src/snapShot/RegionSnapShotWorker.ts",
82 "src/snapShot/SnapShotAccessibilityWorker.ts",
83 ],
84 clean: false,
85 deps: {
86 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
87 neverBundle: isMainProcessExternal,
88 onlyBundle: false,
89 },
90 },
91 {
92 // boot.cjs requires the other two at runtime, so all three stay separate files.
93 format: "cjs",
94 outDir: "dist-electron",
95 dts: false,
96 sourcemap: true,
97 outExtensions: () => ({ js: ".cjs" }),
98 entry: ["src/boot.ts", "src/compileCache.ts"],
99 clean: false,
100 deps: {
101 neverBundle: (id) => id === "./main.cjs" || id === "./compileCache.cjs",
102 },
103 },
104 {
105 format: "cjs",
106 outDir: "dist-electron",
107 dts: false,
108 sourcemap: true,
109 outExtensions: () => ({ js: ".cjs" }),
110 define: publicConfigDefine,
111 entry: ["src/preload.ts"],
112 deps: {
113 // Sandboxed Electron preloads cannot reliably resolve package imports
114 // from inside the packaged ASAR. Bundle Clerk's preload bridge into the
115 // preload artifact instead of leaving a runtime require() behind.
116 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
117 },
118 },
119 {
120 format: "cjs",
121 outDir: "dist-electron",
122 dts: false,
123 sourcemap: true,
124 outExtensions: () => ({ js: ".cjs" }),
125 entry: ["src/preview-pick-preload.ts"],
126 deps: {
127 alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
128 },
129 },
130 {
131 format: "cjs",
132 outDir: "dist-electron",
133 dts: false,
134 sourcemap: true,
135 outExtensions: () => ({ js: ".cjs" }),
136 entry: ["src/preview-pip-preload.ts"],
137 },
138 {
139 // Sandboxed preloads must be self-contained, without shared runtime chunks.
140 format: "cjs",
141 outDir: "dist-electron",
142 dts: false,
143 sourcemap: true,
144 outExtensions: () => ({ js: ".cjs" }),
145 entry: ["src/mac-permission-preload.ts"],
146 },
147 ],
148 test: {
149 include: [...defaultInclude, "../../native/kde-snap-shot/src/*.test.ts"],
150 // The Windows lane runs workspace suites concurrently; filesystem-heavy
151 // desktop integration tests can exceed Vitest's 5 second default there.
152 testTimeout: 15_000,
153 setupFiles: [
154 "../../packages/shared/src/testing/longTempDir.ts",
155 "../../packages/shared/src/testing/providerEnv.ts",
156 ],
157 },
158});