-
-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathvite.config.mjs
More file actions
179 lines (169 loc) · 4.47 KB
/
Copy pathvite.config.mjs
File metadata and controls
179 lines (169 loc) · 4.47 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import path from 'path'
import { fileURLToPath } from 'url'
import vue from '@vitejs/plugin-vue'
import { defineConfig, loadEnv } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
import * as pkgJson from './package.json'
import { globSync } from 'glob'
// Get __dirname equivalent for ESM
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const vuetifyComponents = globSync(
'node_modules/vuetify/lib/components/V*',
).map((file) => file.replace('node_modules/vuetify/lib', 'vuetify'))
const distFolder = path.resolve(__dirname, 'dist')
const proxyScheme = process.env.SERVER_SSL ? 'https' : 'http'
const proxyHostname = process.env.SERVER_HOST
? process.env.SERVER_HOST
: 'localhost'
const proxyPort = process.env.SERVER_PORT ? process.env.SERVER_PORT : '8091'
const ingressToken = process.env.INGRESS_TOKEN
const proxyURL = process.env.SERVER_URL
? process.env.SERVER_URL
: `${proxyScheme}://${proxyHostname}:${proxyPort}`
const headers = ingressToken
? {
headers: { cookie: `ingress_session=${ingressToken}` },
}
: {}
// const proxyWebSocketScheme = process.env.SERVER_SSL ? 'wss' : 'ws'
// const proxyWebSocketURL = `${proxyWebSocketScheme}://${proxyHostname}:${proxyPort}`
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
const env = loadEnv(mode, process.cwd())
process.env.VITE_TITLE = 'Z-Wave JS UI'
process.env.VITE_VERSION = pkgJson.version
process.env.VITE_API_ENDPOINT = proxyURL
return {
base: './',
// Optimize dependencies to prevent reloads during development
optimizeDeps: {
include: [
...vuetifyComponents.filter(
// VOverflowBtn has an issue during optimization, see https://github.com/vuetifyjs/vuetify-loader/issues/350#issuecomment-3129253379
(dep) => !dep.includes('VOverflowBtn'),
),
],
},
plugins: [
vue(),
vuetify({
template: {
transformAssetUrls,
},
autoImport: {
labs: true,
directives: true,
},
}),
VitePWA({
// do not reload application automatically but show a popup to user
registerType: 'prompt',
// when using inject manifes you can provide your own service worker
strategies: 'injectManifest',
// register service worker manually
injectRegister: false,
// https://vite-pwa-org.netlify.app/guide/inject-manifest.html#plugin-configuration-2
srcDir: 'src',
filename: 'sw.js',
devOptions: {
enabled: true,
type: 'module',
/* other options */
},
workbox: {
cleanupOutdatedCaches: true,
globIgnores: ['**/api/**'],
},
manifest: {
name: process.env.VITE_TITLE,
description: process.env.VITE_TITLE,
short_name: process.env.VITE_TITLE,
theme_color: '#ffffff',
background_color: '#2196F3',
icons: [
{
src: 'pwa-64x64.png',
sizes: '64x64',
type: 'image/png',
},
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any',
},
{
src: 'maskable-icon-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
},
}),
],
resolve: {
alias: [
{
find: /^@\/(.+)/,
replacement: `${path.resolve(__dirname, 'src')}/$1`,
},
{
find: /^@server\/(.+)/,
replacement: `${path.resolve(__dirname, 'server')}/$1`,
},
],
preserveSymlinks: true,
},
define: {
__APP_ENV__: JSON.stringify(env.APP_ENV),
},
server: {
port: 8092,
https: process.env.SERVER_SSL
? {
key: path.resolve(__dirname, 'certs/server.key'),
cert: path.resolve(__dirname, 'certs/server.crt'),
}
: false,
base: distFolder,
host: '0.0.0.0',
proxy: {
'/socket.io': {
// not working, see https://github.com/vitejs/vite/issues/4124
target: proxyURL,
ws: true,
secure: false, // allow self signed certificates
changeOrigin: true,
...headers,
},
'/health': {
target: proxyURL,
secure: false,
changeOrigin: true,
...headers,
},
'/api': {
target: proxyURL,
secure: false,
changeOrigin: true,
...headers,
},
},
},
build: {
outDir: distFolder,
sourcemap: false,
emptyOutDir: true,
chunkSizeWarningLimit: 1600,
},
}
})