forked from vernemq/vmq_webadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
157 lines (155 loc) · 4.89 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
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
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
import SvgLoader from 'vite-svg-loader'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import VueRouter from 'unplugin-vue-router/vite'
import Layouts from 'vite-plugin-vue-meta-layouts'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import Modify from '@kingyue/rollup-plugin-modify'
import * as mdicons from '@mdi/js'
const mdi: Record<string, string> = {}
Object.keys(mdicons).forEach((key) => {
const value = (mdicons as Record<string, string>)[key]
mdi[
key.replace(
/[A-Z]+(?![a-z])|[A-Z0-9]/g,
($, ofs) => (ofs ? '-' : '') + $.toLowerCase(),
)
] = value
})
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
Modify({
exclude: ['node_modules/**'],
find: /\b(?<![/\w])(mdi-[\w-]+)\b(?!\.)/,
replace: (match: string) => {
if (mdi[match]) {
return mdi[match]
} else {
console.warn('[plugin-modify] No matched svg icon for ' + match)
return match
}
},
sourcemap: false,
}),
VueRouter({ importMode: 'sync', dts: './src/typed-router.d.ts' }),
Vue({ template: { transformAssetUrls } }),
SvgLoader({
svgoConfig: {
plugins: [
'cleanupEnableBackground',
'removeDoctype',
'removeMetadata',
'removeComments',
'removeXMLNS',
'removeXMLProcInst',
'sortDefsChildren',
'convertTransform',
{
name: 'addClassesToSVGElement',
params: { className: 'v-icon__svg' },
},
],
},
}),
Layouts(),
Vuetify({ autoImport: true }),
Components({ dts: './src/components.d.ts', types: [] }),
AutoImport({
imports: [
'vue',
'pinia',
VueRouterAutoImports,
{
vuetify: [
'useTheme',
'useRtl',
'useLocale',
'useDisplay',
'useLayout',
],
},
],
dts: 'src/auto-imports.d.ts',
dirs: ['src/stores'],
}),
],
server: {
proxy: {
'/webuiapi/v1/nodefwd/self/': {
target: 'http://127.0.0.1:8888',
changeOrigin: true,
secure: false,
headers: { 'x-api-key': '' },
rewrite: (path) => path.replace(/^\/webuiapi\/v1\/nodefwd\/self\//, ''),
configure: (proxy, _options) => {
proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err);
});
proxy.on('proxyReq', (proxyReq, req, _res) => {
console.log('Sending Request to the Target a:', req.method, req.url);
});
proxy.on('proxyRes', (proxyRes, req, _res) => {
console.log('Received Response from the Target a:', proxyRes.statusCode, req.url);
});
},
},
'/webuiapi/v1/nodefwd/VerneMQ@127.0.0.1/': {
target: 'http://127.0.0.1:8888',
changeOrigin: true,
secure: false,
headers: { 'x-api-key': '' },
rewrite: (path) => path.replace(/^\/webuiapi\/v1\/nodefwd\/VerneMQ@127.0.0.1\//, ''),
configure: (proxy, _options) => {
proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err);
});
proxy.on('proxyReq', (proxyReq, req, _res) => {
console.log('Sending Request to the Target a:', req.method, req.url);
});
proxy.on('proxyRes', (proxyRes, req, _res) => {
console.log('Received Response from the Target a:', proxyRes.statusCode, req.url);
});
},
},
'/webuiapi/v1/nodefwd/VerneMQ@127.0.0.2/': {
target: 'http://127.0.0.2:8888',
changeOrigin: true,
secure: false,
headers: { 'x-api-key': 'E57mFERHoFw6QxUiqjldyILOx8IToB0m' },
rewrite: (path) => path.replace(/^\/webuiapi\/v1\/nodefwd\/VerneMQ@127.0.0.2\//, ''),
configure: (proxy, _options) => {
proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err);
});
proxy.on('proxyReq', (proxyReq, req, _res) => {
console.log('Sending Request to the Target c :', req.method, req.url);
});
proxy.on('proxyRes', (proxyRes, req, _res) => {
console.log('Received Response from the Target c:', proxyRes.statusCode, req.url);
});
},
},
cors:false
}
},
css: {
devSourcemap: true,
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
test: {
globals: true,
include: ['test/**/*.test.ts', 'src/**/__tests__/*'],
environment: 'jsdom',
setupFiles: ['./test/setup.ts'],
server: { deps: { inline: ['vuetify'] } },
},
})