-
Notifications
You must be signed in to change notification settings - Fork 18
/
vite.config.ts
74 lines (64 loc) · 2.03 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
/* eslint-disable @typescript-eslint/no-restricted-imports */
import { defineConfig, PluginOption } from 'vite'
import react from '@vitejs/plugin-react'
import replace from '@rollup/plugin-replace'
import removeConsole from 'vite-plugin-remove-console'
import tsconfigPaths from 'vite-tsconfig-paths'
import { comlink } from 'vite-plugin-comlink'
import { pwaPlugins } from './environments/pwa/pwa.vite'
import { chromePlugins } from './environments/chrome/chrome.vite'
import { firefoxPlugins } from './environments/firefox/firefox.vite'
const replaceOptions = { __DATE__: new Date().toISOString(), __RELOAD_SW__: 'false' }
const isDev = process.env.NODE_ENV === 'development'
const TARGET = process.env.TARGET || 'pwa'
const TARGET_IS_PWA = TARGET === 'pwa'
let targetPlugins: PluginOption[] = []
if (TARGET === 'pwa') {
targetPlugins = pwaPlugins
} else if (TARGET === 'chrome') {
targetPlugins = chromePlugins()
} else if (TARGET === 'firefox') {
targetPlugins = firefoxPlugins()
}
const reload = process.env.RELOAD_SW === 'true'
if (reload) {
replaceOptions.__RELOAD_SW__ = 'true'
}
// https://vitejs.dev/config/
export default defineConfig({
define: {
__TARGET__: JSON.stringify(TARGET),
},
plugins: [
comlink(),
react(),
targetPlugins,
// @ts-expect-error this was part of the original setup, it works but probably needs to be updated
replace(replaceOptions),
removeConsole(),
tsconfigPaths(),
],
esbuild: {
// https://github.com/vitejs/vite/discussions/7920#discussioncomment-2709119
drop: isDev ? [] : ['console', 'debugger'],
logLevel: 'silent',
},
build: {
outDir: TARGET_IS_PWA ? './dist' : `./environments/${TARGET}/dist`,
emptyOutDir: true,
rollupOptions: { external: TARGET_IS_PWA ? undefined : ['virtual:pwa-register/react'] },
},
base: TARGET_IS_PWA ? '/llm-x/' : undefined,
worker: {
rollupOptions: {
logLevel: 'silent',
},
plugins: () => [comlink()],
},
preview: {
port: 5173,
strictPort: true,
host: true,
cors: true,
},
})