forked from zwave-js/zwave-js-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
144 lines (137 loc) · 3.37 KB
/
vite.config.mjs
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
import path from 'path'
import vue2 from '@vitejs/plugin-vue2'
import { defineConfig, loadEnv } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import * as pkgJson from './package.json'
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: './',
plugins: [
vue2(),
VitePWA({
registerType: 'autoUpdate',
strategies: 'injectManifest',
injectRegister: 'auto',
// 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: {
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, 'src')}/$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,
},
}
})