-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathvite.config.ts
More file actions
95 lines (91 loc) · 3.36 KB
/
vite.config.ts
File metadata and controls
95 lines (91 loc) · 3.36 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
import { defineConfig } from 'electron-vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import { createRequire } from 'module';
const _require = createRequire(import.meta.url);
// Load Emotiv SDK keys from keys.js and expose them as VITE_* env vars so that
// import.meta.env.VITE_* works in the renderer in both dev and production.
// Environment variables always take precedence over keys.js values.
try {
const keys: {
CLIENT_ID?: string;
CLIENT_SECRET?: string;
LICENSE_ID?: string;
} = _require('./keys.js');
if (keys.CLIENT_ID) process.env.VITE_CLIENT_ID ??= keys.CLIENT_ID;
if (keys.CLIENT_SECRET) process.env.VITE_CLIENT_SECRET ??= keys.CLIENT_SECRET;
if (keys.LICENSE_ID) process.env.VITE_LICENSE_ID ??= keys.LICENSE_ID;
} catch {
// keys.js may not exist in CI environments
}
export default defineConfig({
// ------------------------------------------------------------------
// Main process — electron-vite defaults to src/main/index.ts
// ------------------------------------------------------------------
main: {
resolve: {
alias: {
'@main': path.resolve(__dirname, 'src/main'),
'@renderer': path.resolve(__dirname, 'src/renderer'),
},
},
},
// ------------------------------------------------------------------
// Preload scripts — main window only; viewer preload is built by
// internals/scripts/BuildViewers.js (postbuild npm hook)
// ------------------------------------------------------------------
preload: {},
// ------------------------------------------------------------------
// Renderer (React + Vite dev server)
// ------------------------------------------------------------------
renderer: {
// Serve the pyodide runtime files as static assets so Vite does NOT
// transform them. Files in publicDir are served verbatim at the root URL:
// /pyodide/pyodide.mjs, /pyodide/pyodide.asm.js, /packages/*.whl, etc.
publicDir: path.resolve(__dirname, 'src/renderer/utils/webworker/src'),
plugins: [
react({
jsxRuntime: 'classic', // React 16 does not ship react/jsx-runtime
babel: {
plugins: [
// Legacy decorator support (used throughout the codebase)
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
],
},
}),
],
css: {
modules: {
localsConvention: 'camelCase',
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
},
resolve: {
alias: {
'@renderer': path.resolve(__dirname, 'src/renderer'),
// Browser-compatible path utilities (pathe = modern drop-in for Node's path)
path: 'pathe',
events: 'events',
},
},
optimizeDeps: {
include: ['@neurosity/pipes'],
// Prevent Vite from pre-bundling pyodide. In dev mode it will be served
// raw from node_modules via /@fs/, which is what pyodide.mjs expects.
exclude: ['pyodide'],
},
worker: {
// ES module workers are required for the CDN import in webworker.js.
format: 'es',
},
build: {
rollupOptions: {
// viewer.html + viewer.ts are handled by viewerRendererPlugin above
input: {
index: path.resolve(__dirname, 'src/renderer/index.html'),
},
},
},
},
});