-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.main.config.ts
More file actions
64 lines (62 loc) · 2.79 KB
/
Copy pathvite.main.config.ts
File metadata and controls
64 lines (62 loc) · 2.79 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
import { defineConfig, loadEnv } from 'vite';
import path from 'path';
// https://vitejs.dev/config
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, __dirname, '');
return {
define: {
// Injected at build time from the SENTRY_DSN env var (set as a GitHub
// Actions secret). Empty string in dev → Sentry is a no-op.
'process.env.SENTRY_DSN': JSON.stringify(env.SENTRY_DSN ?? ''),
},
resolve: {
alias: {
'@main': path.resolve(__dirname, 'src/main'),
'@shared': path.resolve(__dirname, 'src/shared'),
},
},
plugins: [],
build: {
// 'hidden' still emits source maps (uploaded to Sentry via sentry-cli in the
// forge packageAfterCopy hook) but omits the sourceMappingURL comment, so maps
// are never referenced by — or shipped to — end users.
sourcemap: 'hidden',
rollupOptions: {
// Optional native modules used by ws / @google/genai — not needed at runtime.
// @aws-sdk/* and @smithy/* were previously external but that breaks packaged
// builds: with npm workspaces hoisting, those packages live at the workspace
// root node_modules/ which electron-forge never copies into the .asar.
// Bundling them with Vite is the correct fix.
external: [
'bufferutil',
'utf-8-validate',
],
// Suppress the "circular dependency" warnings emitted by @smithy's export*
// re-export graph — they are harmless build-time noise.
onwarn(warning, defaultHandler) {
const isAwsSmitthy = (s?: string) => s?.includes('@smithy') || s?.includes('@aws-sdk');
if (warning.ids?.some(isAwsSmitthy)) return;
if (isAwsSmitthy(warning.message)) return;
defaultHandler(warning);
},
output: {
// pdfjs-dist (bundled via pdf-parse) has top-level `new DOMMatrix()` that runs
// at module evaluation time. Its own polyfill loads @napi-rs/canvas via the
// native `.node` binding, which fails in packaged Electron builds due to ABI
// mismatch — leaving globalThis.DOMMatrix undefined and crashing on startup.
// @napi-rs/canvas/geometry.js is pure JavaScript (no native binding) and
// always loads successfully. This banner runs before any module code in the
// bundle, guaranteeing DOMMatrix is defined before pdfjs is evaluated.
banner: [
'try {',
' const _geo = require(\'@napi-rs/canvas/geometry\');',
' if (!globalThis.DOMMatrix) globalThis.DOMMatrix = _geo.DOMMatrix;',
' if (!globalThis.DOMRect) globalThis.DOMRect = _geo.DOMRect;',
' if (!globalThis.DOMPoint) globalThis.DOMPoint = _geo.DOMPoint;',
'} catch (_e) { /* geometry.js unavailable — DOMMatrix may crash later */ }',
].join('\n'),
},
},
},
};
});