-
Notifications
You must be signed in to change notification settings - Fork 984
Expand file tree
/
Copy pathvite.config.ts
More file actions
97 lines (93 loc) · 2.68 KB
/
vite.config.ts
File metadata and controls
97 lines (93 loc) · 2.68 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import electron from 'vite-plugin-electron';
import renderer from 'vite-plugin-electron-renderer';
import { resolve } from 'path';
import { existsSync, readFileSync } from 'fs';
function getExtensionPackages(): Set<string> {
try {
const manifestPath = resolve(__dirname, 'clawx-extensions.json');
if (!existsSync(manifestPath)) return new Set();
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
const allIds: string[] = [
...(manifest.extensions?.main ?? []),
...(manifest.extensions?.renderer ?? []),
];
const pkgs = new Set<string>();
for (const id of allIds) {
if (id.startsWith('builtin/')) continue;
const parts = id.split('/');
pkgs.add(parts[0].startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]);
}
return pkgs;
} catch {
return new Set();
}
}
const extensionPackages = getExtensionPackages();
function isMainProcessExternal(id: string): boolean {
if (!id || id.startsWith('\0')) return false;
if (id.startsWith('.') || id.startsWith('/') || /^[A-Za-z]:[\\/]/.test(id)) return false;
if (id.startsWith('@/') || id.startsWith('@electron/')) return false;
for (const pkg of extensionPackages) {
if (id === pkg || id.startsWith(pkg + '/')) return false;
}
return true;
}
// https://vitejs.dev/config/
export default defineConfig({
// Required for Electron: all asset URLs must be relative because the renderer
// loads via file:// in production. vite-plugin-electron-renderer sets this
// automatically, but we declare it explicitly so the intent is clear and the
// build remains correct even if plugin order ever changes.
base: './',
plugins: [
react(),
electron([
{
// Main process entry file
entry: 'electron/main/index.ts',
onstart(options) {
options.startup();
},
vite: {
build: {
outDir: 'dist-electron/main',
rollupOptions: {
external: isMainProcessExternal,
},
},
},
},
{
// Preload scripts entry file
entry: 'electron/preload/index.ts',
onstart(options) {
options.reload();
},
vite: {
build: {
outDir: 'dist-electron/preload',
rollupOptions: {
external: ['electron'],
},
},
},
},
]),
renderer(),
],
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'@electron': resolve(__dirname, 'electron'),
},
},
server: {
port: 5173,
},
build: {
outDir: 'dist',
emptyOutDir: true,
},
});