Files
ospab.host/ospabhost/frontend/vite.config.ts
ospab a408184851 fix: Восстановлена генерация sitemap.xml
- Добавлен плагин автогенерации sitemap при сборке frontend
- Обновлен nginx.conf для fallback на backend sitemap
- Sitemap включает русские и английские версии всех страниц
- Поддержка hreflang для SEO
2026-01-14 14:50:17 +03:00

121 lines
4.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { copyFileSync, writeFileSync } from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// Функция для генерации sitemap.xml
function generateSitemap() {
const baseUrl = 'https://ospab.host';
const lastmod = new Date().toISOString().split('T')[0];
const pages = [
{ loc: '/', priority: '1.0', changefreq: 'weekly' },
{ loc: '/about', priority: '0.9', changefreq: 'monthly' },
{ loc: '/login', priority: '0.7', changefreq: 'monthly' },
{ loc: '/register', priority: '0.8', changefreq: 'monthly' },
{ loc: '/blog', priority: '0.85', changefreq: 'daily' },
{ loc: '/tariffs', priority: '0.9', changefreq: 'weekly' },
{ loc: '/s3plans', priority: '0.9', changefreq: 'weekly' },
{ loc: '/terms', priority: '0.5', changefreq: 'yearly' },
{ loc: '/privacy', priority: '0.5', changefreq: 'yearly' },
];
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n';
for (const page of pages) {
// Русская версия (без префикса)
xml += ' <url>\n';
xml += ` <loc>${baseUrl}${page.loc}</loc>\n`;
xml += ` <lastmod>${lastmod}</lastmod>\n`;
xml += ` <priority>${page.priority}</priority>\n`;
xml += ` <changefreq>${page.changefreq}</changefreq>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="ru" href="${baseUrl}${page.loc}"/>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="en" href="${baseUrl}/en${page.loc}"/>\n`;
xml += ' </url>\n';
// Английская версия (с префиксом /en)
xml += ' <url>\n';
xml += ` <loc>${baseUrl}/en${page.loc}</loc>\n`;
xml += ` <lastmod>${lastmod}</lastmod>\n`;
xml += ` <priority>${page.priority}</priority>\n`;
xml += ` <changefreq>${page.changefreq}</changefreq>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="ru" href="${baseUrl}${page.loc}"/>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="en" href="${baseUrl}/en${page.loc}"/>\n`;
xml += ' </url>\n';
}
xml += '</urlset>';
return xml;
}
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
{
name: 'copy-service-worker',
writeBundle() {
// Копируем service worker в dist при сборке
try {
copyFileSync(
resolve(__dirname, 'public/service-worker.js'),
resolve(__dirname, 'dist/service-worker.js')
)
console.log('✅ Service worker скопирован в dist/')
} catch (error) {
console.error('❌ Ошибка копирования service worker:', error)
}
}
},
{
name: 'generate-sitemap',
writeBundle() {
// Генерируем sitemap.xml при сборке
try {
const sitemapContent = generateSitemap();
writeFileSync(
resolve(__dirname, 'dist/sitemap.xml'),
sitemapContent,
'utf-8'
);
console.log('✅ Sitemap.xml сгенерирован в dist/');
} catch (error) {
console.error('❌ Ошибка генерации sitemap:', error);
}
}
}
],
build: {
target: 'es2015', // Современные браузеры, уменьшаем полифилы
cssCodeSplit: true,
rollupOptions: {
output: {
manualChunks: {
// Разделяем большие зависимости
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
'ui-vendor': ['react-qr-code'],
}
}
},
minify: 'terser',
terserOptions: {
compress: {
drop_console: true, // Убираем console.log в production
drop_debugger: true,
pure_funcs: ['console.log', 'console.info'] // Удаляем конкретные функции
}
},
chunkSizeWarningLimit: 600 // Увеличим лимит предупреждения
},
server: {
// Для dev сервера public файлы доступны из корня автоматически
port: 3000
}
})