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

vite.config.ts

84 lines2.4 KB

1import { defineConfig } from "vite-plus";
2​
3import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
4​
5const repoEnv = loadRepoEnv();
6const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1";
7const publicConfigDefine = {
8 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
9 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
10 ),
11};
12​
13export default defineConfig({
14 run: {
15 tasks: {
16 build: {
17 command: "node scripts/build-preview-annotation-css.mjs && vp pack",
18 dependsOn: ["t3#build"],
19 cache: false,
20 },
21 dev: {
22 command:
23 "node scripts/build-preview-annotation-css.mjs && cross-env T3CODE_DESKTOP_DEV=1 vp pack --watch",
24 dependsOn: ["t3#build"],
25 cache: false,
26 },
27 "dev:bundle": {
28 command: "node scripts/build-preview-annotation-css.mjs && vp pack --watch",
29 cache: false,
30 },
31 "dev:electron": {
32 command: "node scripts/dev-electron.mjs",
33 dependsOn: ["t3#build"],
34 cache: false,
35 },
36 },
37 },
38 pack: [
39 {
40 format: "cjs",
41 outDir: "dist-electron",
42 sourcemap: true,
43 outExtensions: () => ({ js: ".cjs" }),
44 define: publicConfigDefine,
45 entry: ["src/main.ts"],
46 clean: true,
47 deps: {
48 alwaysBundle: (id) => id.startsWith("@t3tools/"),
49 },
50 ...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
51 },
52 {
53 format: "cjs",
54 outDir: "dist-electron",
55 sourcemap: true,
56 outExtensions: () => ({ js: ".cjs" }),
57 define: publicConfigDefine,
58 entry: ["src/preload.ts"],
59 deps: {
60 // Sandboxed Electron preloads cannot reliably resolve package imports
61 // from inside the packaged ASAR. Bundle Clerk's preload bridge into the
62 // preload artifact instead of leaving a runtime require() behind.
63 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
64 },
65 },
66 {
67 format: "cjs",
68 outDir: "dist-electron",
69 sourcemap: true,
70 outExtensions: () => ({ js: ".cjs" }),
71 entry: ["src/preview-pick-preload.ts"],
72 deps: {
73 alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
74 },
75 },
76 {
77 format: "cjs",
78 outDir: "dist-electron",
79 sourcemap: true,
80 outExtensions: () => ({ js: ".cjs" }),
81 entry: ["src/preview-pip-preload.ts"],
82 },
83 ],
84});