-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
95 lines (87 loc) · 2.56 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
/* eslint-disable node/prefer-global/process */
import { readFileSync } from 'node:fs'
import { fileURLToPath, URL } from 'node:url'
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
import vue from '@vitejs/plugin-vue'
import { defineConfig, loadEnv } from 'vite'
import vuetify from 'vite-plugin-vuetify'
import { parseString } from 'xml2js'
import pkg from './package.json'
import { slugify } from './src/main/webapp/src/utils/stringUtils.ts'
// https://vitejs.dev/config/
export default ({ mode }: { mode: string }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
const appName = JSON.stringify(process.env.VITE_APP_NAME)
const appSlug = JSON.stringify(process.env.VITE_APP_SLUG ? process.env.VITE_APP_SLUG : slugify(appName))
const backVersion = (): string => {
let version
const pomXml = readFileSync('./pom.xml', 'utf8')
parseString(pomXml, (err, result) => {
if (err)
console.error(err)
else version = result.project.version[0]
})
return `${version}`
}
const appsVersions = (): string => {
return Object.entries(pkg.dependencies)
.filter(dep => dep[0].startsWith('@gip-recia/'))
.map(([key, value]) => `\n - ${key} ${value}`)
.join('')
}
const infoLog = (): string => {
return JSON.stringify(`Version: ${backVersion()}\n\nApps: ${appsVersions()}`)
}
return defineConfig({
base: `${process.env.VITE_BASE_URI}/ui`,
root: './src/main/webapp',
envDir: '../../../',
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: tag =>
[
'extended-uportal-header',
'extended-uportal-footer',
'tldraw-editor',
'wisemapping-editor',
].includes(tag),
},
},
}),
vuetify({ styles: 'sass' }),
VueI18nPlugin({}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src/main/webapp/src', import.meta.url)),
},
},
optimizeDeps: {
include: ['vuetify'],
},
server: {
proxy: {
'^(?:/[a-zA-Z0-9_-]+)?/api': {
target: process.env.VITE_PROXY_API_URL,
changeOrigin: true,
},
},
},
build: {
rollupOptions: {
output: {
assetFileNames: 'assets/[name].[ext]',
entryFileNames: 'assets/[name].js',
chunkFileNames: 'assets/[name].js',
},
},
},
define: {
__APP_NAME__: appName,
__APP_SLUG__: appSlug,
__INFO_LOG__: infoLog(),
},
})
}