59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url';
|
||
import react from '@vitejs/plugin-react';
|
||
import { defineConfig } from 'vite';
|
||
import { VitePWA } from 'vite-plugin-pwa';
|
||
|
||
export default defineConfig({
|
||
plugins: [
|
||
react(),
|
||
VitePWA({
|
||
registerType: 'autoUpdate',
|
||
injectRegister: 'auto',
|
||
manifest: {
|
||
name: 'Обходы',
|
||
short_name: 'Обходы',
|
||
description: 'Обходы объектов: маршруты, отметки, фото и видео',
|
||
lang: 'ru',
|
||
theme_color: '#2563eb',
|
||
background_color: '#f5f7fb',
|
||
display: 'standalone',
|
||
start_url: '/',
|
||
icons: [
|
||
{ src: '/icon-192.png', sizes: '192x192', type: 'image/png' },
|
||
{ src: '/icon-512.png', sizes: '512x512', type: 'image/png' },
|
||
],
|
||
},
|
||
workbox: {
|
||
navigateFallback: '/index.html',
|
||
navigateFallbackDenylist: [/^\/api\//, /^\/tiles\//],
|
||
globPatterns: ['**/*.{js,css,html,svg,png,woff2}'],
|
||
runtimeCaching: [
|
||
{
|
||
// Тайлы карты: сначала кэш — карта открывается без сети там, где её уже смотрели.
|
||
urlPattern: ({ url }) => url.pathname.startsWith('/tiles/') || url.hostname.endsWith('tile.openstreetmap.org'),
|
||
handler: 'CacheFirst',
|
||
options: {
|
||
cacheName: 'map-tiles',
|
||
expiration: { maxEntries: 5000, maxAgeSeconds: 60 * 60 * 24 * 60 },
|
||
cacheableResponse: { statuses: [0, 200] },
|
||
},
|
||
},
|
||
],
|
||
},
|
||
}),
|
||
],
|
||
resolve: {
|
||
alias: {
|
||
// Общий пакет берём исходниками, чтобы Vite не возился с CommonJS-сборкой.
|
||
'@patrol/shared': fileURLToPath(new URL('../../packages/shared/src/index.ts', import.meta.url)),
|
||
},
|
||
},
|
||
server: {
|
||
port: 5173,
|
||
proxy: {
|
||
'/api': process.env.API_PROXY || 'http://localhost:8090',
|
||
'/tiles': process.env.API_PROXY || 'http://localhost:8090',
|
||
},
|
||
},
|
||
});
|