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

vite.config.ts

112 lines3.4 KB

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