build(desktop): bundle the main process and stage only its native externals (#11410)

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and GitHub committed 2026-09-13 21:24:20 -07:00
1 parent d81278aa6b
commit 683aa87096
4 files changed
+142 -45

No files matched your search

+12 -1
View File
@@ -1,9 +1,18 @@
import "vite-plus/test/config";
import { defineConfig } from "vite-plus";
import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts";
import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
const repoEnv = loadRepoEnv();
// The main process is bundled the same way the server CLI is: every JS
// dependency is inlined and only packages Node must load from disk stay
// external. The packaged app then installs just those externals, instead of a
// full production install of apps/desktop's dependency tree next to a server
// bundle that already carries its own copy of the same libraries.
const isMainProcessExternal = (id: string) =>
id === "electron" || id.startsWith("electron/") || isDesktopRuntimeExternalDependency(id);
const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1";
const publicConfigDefine = {
__T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
@@ -55,7 +64,9 @@ export default defineConfig({
],
clean: true,
deps: {
alwaysBundle: (id) => id.startsWith("@t3tools/"),
alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
neverBundle: isMainProcessExternal,
onlyBundle: false,
},
...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
},