Repository navigation
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
57 lines (55 loc) · 1.78 KB
/
Copy pathelectron.vite.config.ts
File metadata and controls
57 lines (55 loc) · 1.78 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
import { resolve, isAbsolute } from 'path';
import { defineConfig, externalizeDepsPlugin } from 'electron-vite';
import react from '@vitejs/plugin-react';
import type { Plugin } from 'vite';
// `virtual:pwa-register` is provided by vite-plugin-pwa, which is only wired
// into the web build (src/renderer/vite.config.ts). The shared renderer source
// imports it in PwaUpdatePrompt.tsx, but that component is mounted only on the
// web (see Root.tsx: `{!isElectron && ...}`), so the import is never evaluated
// in Electron. Stub the virtual module here so neither the dev server's import
// analysis nor the production build fails to resolve it.
const pwaRegisterStub = (): Plugin => ({
name: 'pwa-register-stub',
resolveId(id) {
if (id === 'virtual:pwa-register') return '\0virtual:pwa-register';
return undefined;
},
load(id) {
if (id === '\0virtual:pwa-register') {
return 'export const registerSW = () => () => Promise.resolve();';
}
return undefined;
},
});
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
build: {
rollupOptions: {
external: (id) => {
// Don't externalize relative imports or absolute paths (local files)
if (id.startsWith('.') || id.startsWith('/') || isAbsolute(id)) {
return false;
}
// Explicitly externalize fs-extra and other transitive dependencies
if (id === 'fs-extra') {
return true;
}
// Externalize all other node_modules packages
return true;
},
},
},
},
preload: {
plugins: [externalizeDepsPlugin()],
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src'),
},
},
plugins: [react(), pwaRegisterStub()],
},
});