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

vite.config.ts

163 lines5.3 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 // CI bundle jobs skip the Linux browser secret helper; packaging stages one per arch.
29 "build:bundle": {
30 command: "node scripts/build-preview-annotation-css.mjs && vp pack",
31 dependsOn: ["t3#build"],
32 cache: false,
33 },
34 dev: {
35 command:
36 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && cross-env T3CODE_DESKTOP_DEV=1 vp pack --watch",
37 dependsOn: ["t3#build"],
38 cache: false,
39 },
40 "dev:bundle": {
41 command:
42 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack --watch",
43 cache: false,
44 },
45 "dev:electron": {
46 command: "node scripts/dev-electron.mjs",
47 dependsOn: ["t3#build"],
48 cache: false,
49 },
50 // A local tsbuildinfo is leftover build state, not a typecheck input.
51 typecheck: {
52 command: "effect-tsgo tsrs --noEmit",
53 cache: { input: [{ auto: true }, "!*.tsbuildinfo"] },
54 },
55 },
56 },
57 pack: [
58 {
59 format: "cjs",
60 outDir: "dist-electron",
61 dts: false,
62 sourcemap: true,
63 outExtensions: () => ({ js: ".cjs" }),
64 define: publicConfigDefine,
65 outputOptions: { codeSplitting: false },
66 entry: ["src/main.ts"],
67 clean: true,
68 deps: {
69 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
70 neverBundle: isMainProcessExternal,
71 onlyBundle: false,
72 },
73 ...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
74 },
75 {
76 format: "cjs",
77 outDir: "dist-electron",
78 dts: false,
79 sourcemap: true,
80 outExtensions: () => ({ js: ".cjs" }),
81 define: publicConfigDefine,
82 entry: [
83 "src/electron/WindowsForegroundFocusWorker.ts",
84 "src/snapShot/GlobalShiftShortcutWorker.ts",
85 "src/snapShot/RegionSnapShotWorker.ts",
86 "src/snapShot/SnapShotAccessibilityWorker.ts",
87 ],
88 clean: false,
89 deps: {
90 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
91 neverBundle: isMainProcessExternal,
92 onlyBundle: false,
93 },
94 },
95 {
96 // boot.cjs requires the other two at runtime, so all three stay separate files.
97 format: "cjs",
98 outDir: "dist-electron",
99 dts: false,
100 sourcemap: true,
101 outExtensions: () => ({ js: ".cjs" }),
102 entry: ["src/boot.ts", "src/compileCache.ts", "src/serverCompileCache.ts"],
103 clean: false,
104 deps: {
105 neverBundle: (id) => id === "./main.cjs" || id === "./compileCache.cjs",
106 },
107 },
108 {
109 format: "cjs",
110 outDir: "dist-electron",
111 dts: false,
112 sourcemap: true,
113 outExtensions: () => ({ js: ".cjs" }),
114 define: publicConfigDefine,
115 entry: ["src/preload.ts"],
116 deps: {
117 // Sandboxed preloads cannot resolve imports inside ASAR; bundle Clerk's bridge.
118 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
119 },
120 },
121 {
122 format: "cjs",
123 outDir: "dist-electron",
124 dts: false,
125 sourcemap: true,
126 outExtensions: () => ({ js: ".cjs" }),
127 entry: ["src/preview-pick-preload.ts"],
128 deps: {
129 alwaysBundle: (id) =>
130 id === "react-grab" ||
131 id.startsWith("react-grab/") ||
132 id === "@t3tools/shared/keybindingMatching",
133 },
134 },
135 {
136 format: "cjs",
137 outDir: "dist-electron",
138 dts: false,
139 sourcemap: true,
140 outExtensions: () => ({ js: ".cjs" }),
141 entry: ["src/preview-pip-preload.ts"],
142 },
143 {
144 // Sandboxed preloads must be self-contained, without shared runtime chunks.
145 format: "cjs",
146 outDir: "dist-electron",
147 dts: false,
148 sourcemap: true,
149 outExtensions: () => ({ js: ".cjs" }),
150 entry: ["src/mac-permission-preload.ts"],
151 },
152 ],
153 test: {
154 include: [...defaultInclude, "../../native/kde-snap-shot/src/*.test.ts"],
155 // The Windows lane runs workspace suites concurrently; filesystem-heavy
156 // desktop integration tests can exceed Vitest's 5 second default there.
157 testTimeout: 15_000,
158 setupFiles: [
159 "../../packages/shared/src/testing/longTempDir.ts",
160 "../../packages/shared/src/testing/providerEnv.ts",
161 ],
162 },
163});