-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
95 lines (89 loc) · 2.3 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
import { fileURLToPath } from 'url';
import { defineConfig, loadEnv } from 'vite';
import ElectronPlugin, { ElectronOptions } from 'vite-plugin-electron';
import RendererPlugin from 'vite-plugin-electron-renderer';
import EslintPlugin from 'vite-plugin-eslint';
import ReactPlugin from '@vitejs/plugin-react-swc';
import MillionPlugin from 'million/compiler';
import { resolve, dirname } from 'path';
import { rmSync } from 'fs';
import { builtinModules } from 'module';
const isDEV = process.env.NODE_ENV === 'development';
export default defineConfig(({ mode }) => {
process.env = {
...(isDEV
? {
ELECTRON_ENABLE_LOGGING: 'true',
}
: {}),
...process.env,
...loadEnv(mode, process.cwd()),
};
rmSync('dist', { recursive: true, force: true });
const electronPluginConfigs: ElectronOptions[] = [
{
entry: 'src/main/index.ts',
onstart: ({ startup }) => {
startup();
},
vite: {
root: resolve('.'),
build: {
assetsDir: '.',
outDir: 'dist/main',
rollupOptions: {
external: ['electron', ...builtinModules],
},
},
},
},
{
entry: 'src/preload/index.ts',
onstart: ({ reload }) => {
reload();
},
vite: {
root: resolve('.'),
build: {
outDir: 'dist/preload',
},
},
},
];
if (isDEV) {
electronPluginConfigs.push({
entry: 'src/main/index.dev.ts',
vite: {
root: resolve('.'),
build: {
outDir: 'dist/main',
},
},
});
}
return {
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.mts', '.json', '.scss'],
alias: {
'@': resolve(dirname(fileURLToPath(import.meta.url)), 'src'),
},
},
base: './',
root: resolve('./src/renderer'),
publicDir: resolve('./src/renderer/public'),
build: {
sourcemap: isDEV,
minify: !isDEV,
outDir: resolve('./dist'),
},
plugins: [
MillionPlugin.vite({ auto: true }),
ReactPlugin(),
// Docs: https://github.com/gxmari007/vite-plugin-eslint
EslintPlugin(),
// Docs: https://github.com/electron-vite/vite-plugin-electron
ElectronPlugin(electronPluginConfigs),
RendererPlugin(),
],
};
});