Files
web-app/vite.config.js

100 lines
3.0 KiB
JavaScript
Raw Normal View History

2026-08-15 05:27:48 +03:00
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { VitePWA } from 'vite-plugin-pwa'
2026-09-08 17:38:13 +03:00
import { fileURLToPath, URL } from 'node:url'
2026-08-15 05:27:48 +03:00
export default defineConfig({
plugins: [
svelte({
onwarn(warning, handler) {
if (
2026-09-18 20:24:45 +03:00
warning.code.startsWith('a11y_') ||
warning.code === 'slot_element_deprecated' ||
warning.code === 'svelte_self_deprecated' ||
warning.code === 'non_reactive_update'
) {
return;
}
handler(warning);
}
}),
VitePWA({
2026-09-17 04:45:16 +03:00
registerType: 'prompt',
injectRegister: 'auto',
workbox: {
2026-09-18 20:24:45 +03:00
clientsClaim: true,
2026-09-18 21:54:42 +03:00
// mjs добавлен, чтобы pdf.worker.min.mjs попадал в precache
2026-09-18 20:24:45 +03:00
globPatterns: ['**/*.{js,mjs,css,html,ico,png,svg,wasm}'],
2026-09-17 04:45:16 +03:00
navigateFallbackDenylist: [/^\/api\/version/],
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
2026-09-18 20:24:45 +03:00
maxAgeSeconds: 60 * 60 * 24 * 365
2026-09-17 04:45:16 +03:00
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
2026-09-18 21:54:42 +03:00
// ❌ Блок для /\/assets\/.*\.(mjs|js)$/ УДАЛЕН.
// Vite автоматически хэширует имена ассетов (например, pdf.worker.min-abc123.mjs)
// и добавляет их в precache. Использование CacheFirst в runtimeCaching
// для локальных бандлов приводит к тому, что "битые" версии застревают в кэше браузера.
2026-09-17 04:45:16 +03:00
]
},
manifest: {
name: 'UnitPrint',
short_name: 'UnitPrint',
start_url: '/',
display: 'standalone',
background_color: '#ffffff',
2026-09-17 04:45:16 +03:00
theme_color: '#6366f1',
icons: [
{
src: '/icon-192x192.png',
sizes: '192x192',
type: 'image/png'
2026-09-17 04:45:16 +03:00
},
{
src: '/icon-512x512.png',
sizes: '512x512',
type: 'image/png'
}
]
}
})
],
2026-09-08 17:38:13 +03:00
resolve: {
alias: {
$lib: fileURLToPath(new URL('./src/lib', import.meta.url))
}
},
server: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
2026-09-18 03:22:00 +03:00
rewrite: (path) => path.replace(/^\/api/, '')
}
}
2026-09-18 21:30:02 +03:00
},
build: {
target: 'esnext',
rollupOptions: {
output: {
format: 'es',
},
},
},
2026-09-18 21:54:42 +03:00
// ❌ СЕКЦИЯ worker: { format: 'es' } УДАЛЕНА.
// pdfjs-dist использует Classic Worker, где глобальный this !== undefined
// и доступен importScripts(). ES-модули ломают внутреннюю инициализацию pdf.worker.
2026-08-15 05:27:48 +03:00
})