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

vite.config.ts

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