OpenDTU-old/webapp/vite.config.ts
Bernhard Kirchen fcf21ac1d6 keep console.log() when serving webapp
the removal of console and debugger statements by esbuild even when not
building for production seems to be a regression, as these were
definitely working in the past.

this change uses the command parameter to configure esbuild to either
keep or indeed remove the respective statements. they are only kept if
command is not "serve".

to avoid having to indent everything in defineConfig() by one block, the
return statement and closing curly brace were added "inline".
2024-11-03 11:55:34 +01:00

90 lines
2.3 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'
import path from 'path'
// example 'vite.user.ts': export const proxy_target = '192.168.16.107'
let proxy_target;
try {
// eslint-disable-next-line
proxy_target = require('./vite.user.ts').proxy_target;
} catch {
proxy_target = '192.168.20.110';
}
// https://vitejs.dev/config/
export default defineConfig(({ command }) => { return {
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',
chunkSizeWarningLimit: 1024,
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: command !== 'serve' ? ['console', 'debugger'] : []
},
server: {
proxy: {
'^/api': {
target: 'http://' + proxy_target
},
'^/livedata': {
target: 'ws://' + proxy_target,
ws: true,
changeOrigin: true
},
'^/vedirectlivedata': {
target: 'ws://' + proxy_target,
ws: true,
changeOrigin: true
},
'^/batterylivedata': {
target: 'ws://' + proxy_target,
ws: true,
changeOrigin: true
},
'^/console': {
target: 'ws://' + proxy_target,
ws: true,
changeOrigin: true
}
}
}
} })