OpenDTU-old/webapp/vite.config.ts
Bernhard Kirchen 452679e90b make vite proxy target easily configurable
the current proxy target IP address is probably only working for a
single developer at a time. this change introduces a vite.user.ts, which
is ingored by GIT, and which can define a proxy_target that works for
the respective developer.

this does not change the default behavior, as the fallback value is
still the old IP address. if the new vite.user.ts file does not exist,
or if it does not export proxy_target, the fallback value is used.

file vite.config.ts adds an example in a comment of how to bootstrap a
vite.user.ts.
2023-08-09 16:58:58 +02:00

78 lines
1.9 KiB
TypeScript

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import viteCompression from 'vite-plugin-compression';
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
const path = require('path')
// example 'vite.user.ts': export const proxy_target = '192.168.16.107'
let proxy_target;
try {
proxy_target = require('./vite.user.ts').proxy_target;
} catch (error) {
proxy_target = '192.168.178.87';
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
viteCompression({ deleteOriginFile: true, threshold: 0 }),
cssInjectedByJsPlugin(),
VueI18nPlugin({
/* options */
include: path.resolve(path.dirname(fileURLToPath(import.meta.url)), './src/locales/**.json'),
fullInstall: false,
forceStringify: true,
strictMessage: false,
}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap'),
}
},
build: {
// Prevent vendor.css being created
cssCodeSplit: false,
outDir: '../webapp_dist',
emptyOutDir: true,
minify: 'terser',
rollupOptions: {
output: {
// Only create one js file
inlineDynamicImports: true,
// Get rid of hash on js file
entryFileNames: 'js/app.js',
// Get rid of hash on css file
assetFileNames: "assets/[name].[ext]",
},
},
},
esbuild: {
drop: ['console', 'debugger'],
},
server: {
proxy: {
'^/api': {
target: 'http://' + proxy_target
},
'^/livedata': {
target: 'ws://' + proxy_target,
ws: true,
changeOrigin: true
},
'^/console': {
target: 'ws://' + proxy_target,
ws: true,
changeOrigin: true
}
}
}
})