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

vite.config.ts

99 lines3.1 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 sourcemap: true,
46 outExtensions: () => ({ js: ".cjs" }),
47 define: publicConfigDefine,
48 entry: [
49 "src/main.ts",
50 "src/electron/WindowsForegroundFocusWorker.ts",
51 "src/snapShot/GlobalShiftShortcutWorker.ts",
52 "src/snapShot/RegionSnapShotWorker.ts",
53 "src/snapShot/SnapShotAccessibilityWorker.ts",
54 ],
55 clean: true,
56 deps: {
57 alwaysBundle: (id) => id.startsWith("@t3tools/"),
58 },
59 ...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
60 },
61 {
62 format: "cjs",
63 outDir: "dist-electron",
64 sourcemap: true,
65 outExtensions: () => ({ js: ".cjs" }),
66 define: publicConfigDefine,
67 entry: ["src/preload.ts"],
68 deps: {
69 // Sandboxed Electron preloads cannot reliably resolve package imports
70 // from inside the packaged ASAR. Bundle Clerk's preload bridge into the
71 // preload artifact instead of leaving a runtime require() behind.
72 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
73 },
74 },
75 {
76 format: "cjs",
77 outDir: "dist-electron",
78 sourcemap: true,
79 outExtensions: () => ({ js: ".cjs" }),
80 entry: ["src/preview-pick-preload.ts"],
81 deps: {
82 alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
83 },
84 },
85 {
86 format: "cjs",
87 outDir: "dist-electron",
88 sourcemap: true,
89 outExtensions: () => ({ js: ".cjs" }),
90 entry: ["src/preview-pip-preload.ts"],
91 },
92 ],
93 test: {
94 // The Windows lane runs workspace suites concurrently; filesystem-heavy
95 // desktop integration tests can exceed Vitest's 5 second default there.
96 testTimeout: 15_000,
97 setupFiles: ["../../packages/shared/src/testing/longTempDir.ts"],
98 },
99});