-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
71 lines (67 loc) · 2.23 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
import { defineConfig, loadEnv, UserConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { ViteEjsPlugin } from 'vite-plugin-ejs'
import { dirname } from 'path'
import { fileURLToPath } from 'url'
import { useDynamicPublicPath } from 'vite-plugin-dynamic-publicpath'
import banner from 'vite-plugin-banner'
// @ts-ignore
import licenseBanner from './license-banner.txt'
const __dirname = dirname(fileURLToPath(import.meta.url))
// https://vitejs.dev/config/
/** @type {UserConfig} */
export default ({ mode }) => {
const isDev = mode === 'development'
const isProd = mode === 'production'
const env = Object.assign(loadEnv(mode, __dirname, 'NAVIG8_'), process.env)
return defineConfig({
...(isDev && env.NAVIG8_USE_PROXY === 'true'
? {
server: {
proxy: {
'^/repo/.*': {
target: env.NAVIG8_REPO_URL.replace(/\/$/, ''),
changeOrigin: true,
rewrite: (path) => path.replace(/^\/repo/, ''),
},
},
},
}
: {}),
...(env.NAVIG8_BUILD_AS_MANIFEST === 'true'
? {
build: {
manifest: true,
rollupOptions: {
input: path.resolve(__dirname, './src/main.ts'),
},
},
}
: {}),
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
plugins: [
vue(),
env.NAVIG8_BUILD_AS_MANIFEST !== 'true' &&
ViteEjsPlugin((config) => ({
JS: './src/main.ts',
CSS: undefined,
NAVIG8_SEO_TITLE: config.env.NAVIG8_SEO_TITLE ?? '',
NAVIG8_FAVICON: config.env.NAVIG8_FAVICON ?? '',
NAVIG8_METAS: JSON.parse(config.env.NAVIG8_METAS ?? '[]'),
NAVIG8_LINKS: JSON.parse(config.env.NAVIG8_LINKS ?? '[]'),
NAVIG8_TOP_HEAD: config.env.NAVIG8_TOP_HEAD,
NAVIG8_BOTTOM_HEAD: config.env.NAVIG8_BOTTOM_HEAD,
NAVIG8_TOP_BODY: config.env.NAVIG8_TOP_BODY,
NAVIG8_BOTTOM_BODY: config.env.NAVIG8_BOTTOM_BODY,
})),
env.NAVIG8_BUILD_FOR_DOCKER === 'true' && useDynamicPublicPath(),
isProd && banner(licenseBanner),
].filter(Boolean),
envPrefix: 'NAVIG8_',
})
}