Files
web-app/vite.config.js
2026-09-18 21:54:42 +03:00

100 lines
3.0 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: {
clientsClaim: true,
// mjs добавлен, чтобы pdf.worker.min.mjs попадал в precache
globPatterns: ['**/*.{js,mjs,css,html,ico,png,svg,wasm}'],
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
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
// ❌ Блок для /\/assets\/.*\.(mjs|js)$/ УДАЛЕН.
// Vite автоматически хэширует имена ассетов (например, pdf.worker.min-abc123.mjs)
// и добавляет их в precache. Использование CacheFirst в runtimeCaching
// для локальных бандлов приводит к тому, что "битые" версии застревают в кэше браузера.
]
},
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/, '')
}
}
},
build: {
target: 'esnext',
rollupOptions: {
output: {
format: 'es',
},
},
},
// ❌ СЕКЦИЯ worker: { format: 'es' } УДАЛЕНА.
// pdfjs-dist использует Classic Worker, где глобальный this !== undefined
// и доступен importScripts(). ES-модули ломают внутреннюю инициализацию pdf.worker.
})