-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathvite.config.ts
More file actions
125 lines (117 loc) · 3.56 KB
/
vite.config.ts
File metadata and controls
125 lines (117 loc) · 3.56 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
121
122
123
124
125
import { fileURLToPath } from 'node:url';
import twemoji from '@discordapp/twemoji';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import electron from 'vite-plugin-electron/simple';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { Constants } from './src/renderer/constants';
import { Errors } from './src/renderer/utils/errors';
const ALL_EMOJIS = [
...Constants.ALL_READ_EMOJIS,
...Errors.BAD_CREDENTIALS.emojis,
...Errors.MISSING_SCOPES.emojis,
...Errors.NETWORK.emojis,
...Errors.RATE_LIMITED.emojis,
...Errors.UNKNOWN.emojis,
];
const extractSvgFilename = (imgHtml: string) =>
imgHtml
.match(/src="(.*)"/)?.[1]
.split('/')
.pop();
const ALL_EMOJI_SVG_FILENAMES = ALL_EMOJIS.map((emoji) =>
extractSvgFilename(twemoji.parse(emoji, { folder: 'svg', ext: '.svg' })),
);
export default defineConfig(({ command }) => {
const isBuild = command === 'build';
return {
plugins: [
// only run the checker plugin in dev (not during `vite build`)
...(isBuild
? []
: [
checker({
typescript: true,
biome: { dev: { logLevel: ['error'] } },
}),
]),
react({
plugins: [
[
'@swc-contrib/plugin-graphql-codegen-client-preset',
{
artifactDirectory: './src/renderer/utils/api/graphql/generated',
gqlTagName: 'graphql',
},
],
],
}),
tailwindcss(),
electron({
main: {
entry: fileURLToPath(new URL('src/main/index.ts', import.meta.url)),
vite: {
build: {
outDir: fileURLToPath(new URL('build', import.meta.url)),
rollupOptions: {
output: { entryFileNames: 'main.js' },
external: [
'electron',
// TODO - how many of these are truly needed?
'electron-log',
'electron-updater',
'menubar',
],
},
},
},
},
preload: {
input: fileURLToPath(
new URL('src/preload/index.ts', import.meta.url),
),
vite: {
build: {
outDir: fileURLToPath(new URL('build', import.meta.url)),
rollupOptions: { output: { entryFileNames: 'preload.js' } },
},
resolve: { conditions: ['node'] },
},
},
}),
viteStaticCopy({
targets: [
...ALL_EMOJI_SVG_FILENAMES.map((filename) => ({
src: `../../node_modules/@discordapp/twemoji/dist/svg/${filename}`,
dest: 'assets/images/twemoji',
})),
{
src: '../../assets',
dest: '.',
},
],
}),
],
root: 'src/renderer',
publicDir: false as const,
base: './',
build: {
outDir: fileURLToPath(new URL('build', import.meta.url)),
emptyOutDir: true,
},
// Define build-time replacements for the main process bundle.
// During CI builds `process.env.OAUTH_CLIENT_ID` will be injected via the environment.
define: isBuild
? {
'process.env.OAUTH_CLIENT_ID': JSON.stringify(
process.env.OAUTH_CLIENT_ID ?? '',
),
}
: {
// Development Keys - See CONTRIBUTING.md
'process.env.OAUTH_CLIENT_ID': JSON.stringify('Ov23liQIkFs5ehQLNzHF'),
},
};
});