-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.mts
More file actions
140 lines (132 loc) · 4.43 KB
/
Copy pathvite.config.mts
File metadata and controls
140 lines (132 loc) · 4.43 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Plugins
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import Fonts from 'unplugin-fonts/vite'
import Layouts from 'vite-plugin-vue-layouts-next'
import Vue from '@vitejs/plugin-vue'
import VueRouter from 'unplugin-vue-router/vite'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
// Utilities
import { defineConfig, loadEnv } from 'vite'
import { fileURLToPath, URL } from 'node:url'
import XXH, { HashObject } from 'xxhashjs'
import { OutputOptions } from 'rollup'
const hasher: HashObject = XXH.h64()
export default defineConfig(({ mode }) => {
const env: Record<string, string> = loadEnv(mode, process.cwd(), '')
const labRunMode: string = resolveLabRunMode(env)
const baseUrl: string = resolveBaseUrl(labRunMode)
const evitaLabVersionSuffix: string = resolveEvitaLabVersionSuffix(env)
let outputOptions: OutputOptions
if (labRunMode === 'STANDALONE') {
outputOptions = {
chunkFileNames: `assets/[name]-[hash]-${evitaLabVersionSuffix}.js`,
entryFileNames: `assets/[name]-${evitaLabVersionSuffix}.js`,
assetFileNames: `assets/[name]-[hash]-${evitaLabVersionSuffix}[extname]`
}
} else if (labRunMode === 'DRIVER') {
outputOptions = {
inlineDynamicImports: true
}
}
return {
plugins: [
VueRouter({
dts: 'src/typed-router.d.ts',
}),
Layouts(),
AutoImport({
imports: [
'vue',
VueRouterAutoImports,
{
pinia: ['defineStore', 'storeToRefs'],
},
],
dts: 'src/auto-imports.d.ts',
eslintrc: { enabled: true },
vueTemplate: true,
}),
Components({
dts: 'src/components.d.ts'
}),
Vue({
template: { transformAssetUrls },
}),
Vuetify({
autoImport: true,
styles: {
configFile: 'src/styles/settings.scss',
},
}),
Fonts({
fontsource: {
families: [
{
name: 'Roboto',
weights: [100, 300, 400, 500, 700, 900],
styles: ['normal', 'italic'],
},
],
},
}),
],
optimizeDeps: {
exclude: [
'vuetify',
'vue-router',
'unplugin-vue-router/runtime',
'unplugin-vue-router/data-loaders',
'unplugin-vue-router/data-loaders/basic',
],
},
build: {
rollupOptions: {
output: outputOptions,
},
},
define: { 'process.env': {} },
resolve: {
alias: {
'@': fileURLToPath(new URL('src', import.meta.url)),
},
extensions: ['.js', '.json', '.jsx', '.mjs', '.ts', '.tsx', '.vue'],
},
server: {
port: 3000,
strictPort: true,
host: true,
},
base: baseUrl,
css: {
preprocessorOptions: {
sass: {
api: 'modern-compiler',
},
scss: {
api: 'modern-compiler',
},
},
},
}
})
function resolveLabRunMode(env: Record<string, string>): string {
const customLabRunMode: string | undefined = env.VITE_RUN_MODE
if (!customLabRunMode || customLabRunMode.trim().length === 0) {
return 'STANDALONE'
}
return customLabRunMode
}
function resolveBaseUrl(labRunMode: string): string {
switch (labRunMode) {
case 'STANDALONE': return '/lab'
case 'DRIVER': return './'
default: throw new Error(`Unsupported lab run mode ${labRunMode}`)
}
}
function resolveEvitaLabVersionSuffix(env: Record<string, string>): string {
const actualVersion: string | undefined = env.VITE_BUILD_VERSION
const normalizedVersion = actualVersion && actualVersion.length > 0 ? actualVersion : 'dev'
return hasher.update(normalizedVersion).digest().toString(16)
}