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

vite.config.ts

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