Files
web-app/vite.config.js

82 lines
2.1 KiB
JavaScript

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { VitePWA } from 'vite-plugin-pwa'
import { fileURLToPath, URL } from 'node:url'
export default defineConfig({
plugins: [
svelte({
onwarn(warning, handler) {
if (
warning.code.startsWith('a11y_') ||
warning.code === 'slot_element_deprecated' ||
warning.code === 'svelte_self_deprecated' ||
warning.code === 'non_reactive_update'
) {
return;
}
handler(warning);
}
}),
VitePWA({
registerType: 'prompt',
injectRegister: 'auto',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,wasm}'],
// Важно: не кэшируем API endpoint версии
navigateFallbackDenylist: [/^\/api\/version/],
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 год
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
},
manifest: {
name: 'UnitPrint',
short_name: 'UnitPrint',
start_url: '/',
display: 'standalone',
background_color: '#ffffff',
theme_color: '#6366f1',
icons: [
{
src: '/icon-192x192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: '/icon-512x512.png',
sizes: '512x512',
type: 'image/png'
}
]
}
})
],
resolve: {
alias: {
$lib: fileURLToPath(new URL('./src/lib', import.meta.url))
}
},
server: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
})