-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathelectron.vite.config.mjs
More file actions
120 lines (114 loc) · 3.82 KB
/
Copy pathelectron.vite.config.mjs
File metadata and controls
120 lines (114 loc) · 3.82 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import path from 'path'
import inject from '@rollup/plugin-inject'
import typescript from '@rollup/plugin-typescript'
import react from '@vitejs/plugin-react'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import simpleGit from 'simple-git'
import svgr from 'vite-plugin-svgr'
import wasm from 'vite-plugin-wasm'
import pkg from './package.json'
const git = simpleGit()
export default defineConfig(async ({ mode }) => {
const commitHash = (await git.revparse(['--short', 'HEAD'])).trim()
return {
main: {
build: {
sourcemap: mode === 'development',
outDir: 'build/main',
lib: { entry: 'src/main/electron.ts' }
},
resolve: {
extensions: ['.ts', '.js']
},
plugins: [
typescript({ tsconfig: './tsconfig.main.json', outDir: 'build/main' }),
externalizeDepsPlugin({
include: ['@ledgerhq/hw-transport-node-hid-singleton', '@ledgerhq/hw-transport', 'node-hid', 'usb']
})
],
define: {
$COMMIT_HASH: JSON.stringify(commitHash || 'dev'),
$VERSION: JSON.stringify(pkg.version),
$IS_DEV: JSON.stringify(process.env.NODE_ENV !== 'production')
}
},
preload: {
build: {
lib: { entry: 'src/main/preload.ts' },
outDir: 'build/preload',
sourcemap: mode === 'development'
},
plugins: [externalizeDepsPlugin()],
resolve: {
extensions: ['.ts', '.js']
}
},
renderer: {
input: 'src/renderer/index.html',
assetsInclude: ['**/*.wasm'],
build: {
sourcemap: mode === 'development',
outDir: 'build/renderer',
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom', 'react-router-dom'],
crypto: ['crypto-browserify', 'stream-browserify', 'readable-stream']
}
},
plugins: [
inject({
Buffer: ['buffer', 'Buffer']
})
]
},
commonjsOptions: {
transformMixedEsModules: true,
include: [/node_modules/, /@xchainjs\/zcash-js/]
}
},
resolve: {
// NOTE: `crypto-browserify` and its deps `pbkdf2` / `browserify-sign` are
// version-pinned in package.json → resolutions. Newer releases pull a
// readable-stream 2.x build that crashes this renderer bundle at runtime
// ("Cannot read properties of undefined (reading 'slice')"). `yarn build`
// passes regardless, so launch `yarn dev` and confirm the app loads before
// bumping these. See PR #1082.
alias: {
process: 'process/browser',
stream: 'stream-browserify',
crypto: 'crypto-browserify',
assert: 'assert',
path: path.resolve(__dirname, 'empty.js'),
url: path.resolve(__dirname, 'empty.js'),
https: path.resolve(__dirname, 'empty.js'),
http: path.resolve(__dirname, 'empty.js'),
zlib: path.resolve(__dirname, 'empty.js'),
fs: path.resolve(__dirname, 'empty.js')
}
},
optimizeDeps: {
include: ['process', 'buffer', 'assert', '@xchainjs/zcash-js'],
esbuildOptions: {
inject: ['./src/shims/buffer-shim.js']
}
},
plugins: [wasm(), react(), svgr(), typescript({ outDir: 'build/renderer' })],
define: {
'process.env': {}, // TODO: Fix from xchain
global: 'globalThis',
$COMMIT_HASH: JSON.stringify(commitHash || 'dev'),
$VERSION: JSON.stringify(pkg.version),
$IS_DEV: JSON.stringify(process.env.NODE_ENV !== 'production'),
$LOG_LEVEL: JSON.stringify(process.env.VITE_LOG_LEVEL || '')
},
server: {
port: 3000,
host: true,
watch: {
ignored: ['**/.trunk/**']
}
}
}
}
})