-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
63 lines (60 loc) · 1.74 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
import { fromEnv } from '@nordicsemiconductor/from-env'
import preact from '@preact/preset-vite'
import Handlebars from 'handlebars'
import { defineConfig } from 'vite'
import { homepage, version } from './siteInfo.js'
const { apiEndpoint, wsEndpoint } = fromEnv({
apiEndpoint: 'API_ENDPOINT',
wsEndpoint: 'WS_ENDPOINT',
})(process.env)
const replaceInIndex = (data: Record<string, string>) => ({
name: 'replace-in-index',
transformIndexHtml: (source: string): string => {
const template = Handlebars.compile(source)
return template(data)
},
})
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
preact(),
replaceInIndex({
version,
}),
],
base: `${(process.env.BASE_URL ?? '').replace(/\/+$/, '')}/`,
preview: {
host: 'localhost',
port: 8080,
},
server: {
host: 'localhost',
port: 8080,
},
build: {
outDir: './build',
sourcemap: true,
},
resolve: {
alias: [
{ find: '#api/', replacement: '/src/api/' },
{ find: '#components/', replacement: '/src/components/' },
{ find: '#context/', replacement: '/src/context/' },
{ find: '#navigation/', replacement: '/src/navigation/' },
{ find: '#proto/', replacement: '/src/proto/' },
{ find: '#util/', replacement: '/src/util/' },
{ find: '#views/', replacement: '/src/views/' },
],
},
esbuild: {
logOverride: { 'this-is-undefined-in-esm': 'silent' },
},
// string values will be used as raw expressions, so if defining a string constant, it needs to be explicitly quoted
define: {
HOMEPAGE: JSON.stringify(homepage),
VERSION: JSON.stringify(version),
BUILD_TIME: JSON.stringify(new Date().toISOString()),
API_ENDPOINT: JSON.stringify(apiEndpoint.replace(/\/$/g, '')),
WS_ENDPOINT: JSON.stringify(wsEndpoint.replace(/\/$/g, '')),
},
})