-
Notifications
You must be signed in to change notification settings - Fork 31
/
vite.config.ts
115 lines (109 loc) · 2.9 KB
/
vite.config.ts
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
import react from '@vitejs/plugin-react'
import svgr from 'vite-plugin-svgr'
import { join, resolve } from 'path'
import {
bytecodePlugin,
defineConfig,
externalizeDepsPlugin
} from 'electron-vite'
import { statSync } from 'fs'
const srcAliases = ['backend', 'frontend', 'common'].map((aliasName) => {
return {
find: aliasName,
replacement: join(__dirname, 'src', aliasName)
}
})
// only set alias if the proxy-server optional package was not added
try {
statSync(join(__dirname, 'node_modules', '@hyperplay', 'proxy-server'))
} catch (err) {
srcAliases.push(
{
find: '@hyperplay/providers',
replacement: join(__dirname, 'src', 'empty.js')
},
{
find: '@hyperplay/proxy-server',
replacement: join(__dirname, 'src', 'empty.js')
},
{
find: '@hyperplay/extension-importer',
replacement: join(__dirname, 'src', 'empty.js')
},
{
find: '@hyperplay/extension-provider',
replacement: join(__dirname, 'src', 'empty.js')
},
{
find: '@hyperplay/overlay',
replacement: join(__dirname, 'src', 'empty.js')
},
{
find: '@hyperplay/patcher',
replacement: join(__dirname, 'src', 'empty.js')
}
)
}
const dependenciesToNotExternalize = ['@hyperplay/check-disk-space']
const preloads = [
'src/backend/preload.ts',
'src/backend/proxy/providerPreload.ts',
'src/backend/hyperplay_store_preload.ts',
'src/backend/webview_style_preload.ts',
'src/backend/auth_provider_preload.ts'
]
// only set alias if the extension-provider optional package was added
try {
statSync(join(__dirname, 'node_modules', '@hyperplay', 'extension-provider'))
preloads.push(
'node_modules/@hyperplay/extension-provider/src/extensionPreload.ts'
)
} catch (err) {}
export default defineConfig(({ mode }) => ({
main: {
build: {
rollupOptions: {
input: 'src/backend/main.ts'
},
outDir: 'build/main',
minify: mode === 'production',
sourcemap: mode === 'development' ? 'inline' : false
},
resolve: { alias: srcAliases },
plugins: [
externalizeDepsPlugin({ exclude: dependenciesToNotExternalize }),
bytecodePlugin()
]
},
preload: {
build: {
rollupOptions: {
input: preloads
},
outDir: 'build/preload',
minify: mode === 'production',
sourcemap: mode === 'development' ? 'inline' : false
},
resolve: { alias: srcAliases },
plugins: [externalizeDepsPlugin({ exclude: dependenciesToNotExternalize })]
},
renderer: {
root: '.',
build: {
rollupOptions: {
input: resolve('index.html')
},
target: 'esnext',
outDir: 'build',
emptyOutDir: false,
minify: mode === 'production',
sourcemap: mode === 'development' ? 'inline' : false
},
resolve: { alias: srcAliases },
plugins: [svgr(), react()]
},
resolve: {
alias: srcAliases
},
plugins: [svgr()]
}))