forked from OpenEVSE/openevse-gui-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
145 lines (139 loc) · 4.22 KB
/
vite.config.js
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
import { defineConfig, loadEnv } from "vite"
import { svelte } from "@sveltejs/vite-plugin-svelte"
import viteCompression from 'vite-plugin-compression'
import { VitePWA } from 'vite-plugin-pwa'
import { visualizer } from "rollup-plugin-visualizer"
// import { dependencies } from './package.json';
import fs from 'fs'
// function renderChunks(deps) {
// let chunks = {};
// Object.keys(deps).forEach((key) => {
// // if (['luxon', 'svelte-i18n', 'iconify-icon', 'svelte-local-storage-store', 'promise-batching-queue', 'hacktimer', 'bulma-slider', 'svelte-spa-router', 'svelte-spa-chunk'].includes(key)) return;
// chunks[key] = [key];
// });
// return chunks;
//}
const confFolder = './src/components/blocks/configuration/';
function configChunk() {
let files = fs.readdirSync(confFolder, {withFileTypes: true})
.filter(item => !item.isDirectory())
.map(item => confFolder + item.name)
console.log(files)
return files
}
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd())
console.log('mode', { env })
return {
build: {
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['luxon', 'svelte-i18n', 'iconify-icon', 'svelte-local-storage-store', 'hacktimer'],
components: [
'./src/components/ui/Borders.svelte',
'./src/components/ui/Button.svelte',
'./src/components/ui/Checkbox.svelte',
'./src/components/ui/IconButton.svelte',
'./src/components/ui/InputForm.svelte',
'./src/components/ui/Loader.svelte',
'./src/components/ui/RemovableTag.svelte',
'./src/components/ui/Select.svelte',
'./src/components/ui/SliderForm.svelte',
'./src/components/ui/Switch.svelte',
'./src/components/ui/Tabs.svelte',
'./src/components/blocks/main/Limit.svelte'
],
config:
configChunk(),
// ...renderChunks(dependencies),
},
},
},
},
resolve: {
alias: {
"~bulma": "bulma",
},
},
plugins: [
visualizer(),
svelte(),
viteCompression({deleteOriginFile: true, algorithm: "gzip",filter: /\.(js|mjs|json|css|html)$/i}),
VitePWA({
registerType: 'autoUpdate',
injectRegister: null,
selfDestroying: true,
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,gz}']
},
useCredentials: 'true',
devOptions: {
enabled: true
},
includeAssets: ['favicon.ico'],
manifest: {
name: 'OpenEVSE UI',
short_name: 'OpenEVSE',
description: 'OpenEVSE User Interface',
categories: 'car,energy,electric vehicle,ev,charger',
theme_color: 'blue',
background_color: 'hsl(189, 53%, 47%)',
display: 'standalone',
icons: [
{
src: 'pwa-maskable.png',
sizes: '96x96',
type: 'image/png',
purpose: 'any maskable'
},
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png'
}]
}
})
],
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "src/variables.scss" as *;',
},
},
},
base: './',
server: {
host: "0.0.0.0",
proxy: {
'/api': {
target: 'http://' + env.VITE_OPENEVSEHOST,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
},
'/ws': {
target: 'ws://' + env.VITE_OPENEVSEHOST,
ws: true,
},
'/debug/console': {
target: 'ws://' + env.VITE_OPENEVSEHOST,
ws: true,
},
'/evse/console': {
target: 'ws://' + env.VITE_OPENEVSEHOST,
ws: true,
},
'/debug': {
target: 'http://' + env.VITE_OPENEVSEHOST,
changeOrigin: true,
},
'/evse': {
target: 'http://' + env.VITE_OPENEVSEHOST,
changeOrigin: true,
}
}
}
}
});