-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
125 lines (119 loc) · 4.52 KB
/
vite.config.ts
File metadata and controls
125 lines (119 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { resolve } from "node:path";
import { defineConfig, loadEnv } from "vite";
import babel from "@rolldown/plugin-babel";
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
const compilerPreset = reactCompilerPreset();
const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
function readEnvValue(env: Record<string, string>, key: string): string {
return (env[key] ?? process.env[key] ?? "").trim();
}
function buildPostHogEnvDefines(mode: string): Record<string, string> {
const env = loadEnv(mode, process.cwd(), "");
const posthogKey = readEnvValue(env, "POSTHOG_KEY");
const posthogHost = readEnvValue(env, "POSTHOG_HOST") || DEFAULT_POSTHOG_HOST;
const posthogEnabled = readEnvValue(env, "POSTHOG_ENABLED") || "1";
const posthogEnableDev = readEnvValue(env, "POSTHOG_ENABLE_DEV") || "0";
return {
"import.meta.env.VITE_POSTHOG_ENABLE_DEV": JSON.stringify(posthogEnableDev),
"import.meta.env.VITE_POSTHOG_ENABLED": JSON.stringify(posthogEnabled),
"import.meta.env.VITE_POSTHOG_HOST": JSON.stringify(posthogHost),
"import.meta.env.VITE_POSTHOG_KEY": JSON.stringify(posthogKey),
};
}
// Inline ternary instead of importing src/shared/channel.normalizeChannel —
// keeps config loading uniform with tsdown.config.ts. Parity is pinned by
// src/shared/channel.config-parity.test.ts.
const lightcodeChannel = process.env.LIGHTCODE_CHANNEL === "nightly" ? "nightly" : "stable";
export default defineConfig(({ mode }) => ({
plugins: [react(), babel({ presets: [compilerPreset] })],
base: "./",
define: {
...buildPostHogEnvDefines(mode),
__LIGHTCODE_CHANNEL__: JSON.stringify(lightcodeChannel),
},
resolve: {
tsconfigPaths: true,
alias: {
"~file-icons": resolve(__dirname, "node_modules/material-icon-theme/icons"),
},
},
build: {
outDir: "dist/renderer",
emptyOutDir: true,
sourcemap: "hidden",
// Filter modulePreload so the heaviest async chunks (shiki grammars,
// @git-diff-view, xterm) are not parsed by V8 at startup. They load on
// demand when the code path that needs them runs (first code block,
// first git overlay open, first terminal).
modulePreload: {
resolveDependencies: (_filename, deps) =>
deps.filter((dep) => !/(?:^|\/)(shiki-|git-diff-|xterm-|vendor-)/.test(dep)),
},
rolldownOptions: {
output: {
minify: {
compress: {
dropConsole: true,
dropDebugger: true,
},
},
codeSplitting: {
groups: [
{
name: "xterm",
test: /[\\/]node_modules[\\/]@xterm[\\/]/,
priority: 50,
},
{
name: "git-diff",
test: /[\\/]node_modules[\\/]@git-diff-view[\\/]/,
priority: 45,
},
{
name: "monaco",
test: /[\\/]node_modules[\\/](@monaco-editor|monaco-editor)[\\/]/,
priority: 40,
},
{
// Shiki engine + bundle-full glue, BUT not its grammars/themes.
// shiki/bundle-full uses per-language dynamic imports
// (`() => import("@shikijs/langs/typescript")`); leaving
// langs/themes out of any group lets rolldown emit them as
// separate per-language chunks, so V8 only parses the grammars
// actually rendered.
name: "shiki",
test: /[\\/]node_modules[\\/](shiki[\\/]|@shikijs[\\/](?:core|engine-|types|vscode-))/,
priority: 38,
},
{
name: "ui",
test: /[\\/]node_modules[\\/](@heroui|react-aria|@react-stately|@react-types|tailwind-merge|tailwind-variants)[\\/]/,
priority: 35,
},
{
name: "framework",
test: /[\\/]node_modules[\\/](react|react-dom|scheduler|zustand|zod)[\\/]/,
priority: 30,
},
{
// Catch-all for everything not handled above. Excludes
// @shikijs/langs and @shikijs/themes so each grammar/theme
// becomes its own auto-chunk (one per file actually used).
name: "vendor",
test: (id: string) =>
/[\\/]node_modules[\\/]/.test(id) &&
!/[\\/]@shikijs[\\/](?:langs|themes)[\\/]/.test(id),
priority: 10,
},
],
},
},
},
},
server: {
forwardConsole: true,
host: "127.0.0.1",
port: 3100,
strictPort: true,
},
}));