noteJS-react/vite.config.ts

210 lines
6.1 KiB
TypeScript
Raw 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 { VitePWA } from "vite-plugin-pwa";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
VitePWA({
injectRegister: "auto",
includeAssets: [
"icon.svg",
"icons/icon-192x192.png",
"icons/icon-512x512.png",
"manifest.json",
],
// Включаем стратегию для offline работы
strategies: "generateSW",
manifest: {
name: "NoteJS - Система заметок",
short_name: "NoteJS",
description:
"Современная система заметок с поддержкой Markdown, изображений, тегов и календаря",
theme_color: "#007bff",
background_color: "#ffffff",
display: "standalone",
orientation: "portrait-primary",
scope: "/",
start_url: "/",
icons: [
{
src: "/icons/icon-72x72.png",
sizes: "72x72",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-96x96.png",
sizes: "96x96",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-128x128.png",
sizes: "128x128",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-144x144.png",
sizes: "144x144",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-152x152.png",
sizes: "152x152",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-192x192.png",
sizes: "192x192",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-384x384.png",
sizes: "384x384",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "/icons/icon-192x192.png",
sizes: "192x192",
type: "image/png",
purpose: "maskable",
},
{
src: "/icons/icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
workbox: {
// Кэшируем все статические ресурсы для offline работы
globPatterns: ["**/*.{js,css,html,ico,png,svg,woff,woff2,ttf,eot,json}"],
// Стратегия для главной страницы - CacheFirst для offline работы
navigateFallback: "/index.html",
navigateFallbackDenylist: [/^\/api/, /^\/_/],
// Кэширование для offline работы приложения
runtimeCaching: [
{
// Стратегия для корневого пути и index.html
urlPattern: ({ request }) =>
request.destination === 'document' ||
request.url.endsWith('/') ||
request.url.endsWith('/index.html'),
handler: "NetworkFirst",
options: {
cacheName: "html-cache",
expiration: {
maxEntries: 10,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
networkTimeoutSeconds: 3,
},
},
{
// Статические ресурсы (JS, CSS) - кэшируем для offline
urlPattern: /\.(?:js|css|woff|woff2|ttf|eot)$/,
handler: "CacheFirst",
options: {
cacheName: "static-resources-cache",
expiration: {
maxEntries: 200,
maxAgeSeconds: 365 * 24 * 60 * 60, // 1 year
},
},
},
{
urlPattern: /^https:\/\/api\./,
handler: "NetworkFirst",
options: {
cacheName: "api-cache",
expiration: {
maxEntries: 50,
maxAgeSeconds: 60 * 60, // 1 hour
},
networkTimeoutSeconds: 3,
},
},
{
urlPattern: /\/api\//,
handler: "NetworkFirst",
options: {
cacheName: "api-cache-local",
expiration: {
maxEntries: 100,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
networkTimeoutSeconds: 3,
},
},
{
urlPattern: /\/uploads\//,
handler: "CacheFirst",
options: {
cacheName: "uploads-cache",
expiration: {
maxEntries: 200,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
},
},
},
{
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp)$/,
handler: "CacheFirst",
options: {
cacheName: "images-cache",
expiration: {
maxEntries: 100,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
},
},
},
],
cleanupOutdatedCaches: true,
skipWaiting: true,
clientsClaim: true,
},
registerType: "prompt",
devOptions: {
enabled: true,
type: "module",
},
}),
],
server: {
port: 5173,
allowedHosts: ["app.notejs.ru", "localhost"],
proxy: {
"/api": {
target: "http://localhost:3001",
changeOrigin: true,
secure: false,
ws: true,
},
"/uploads": {
target: "http://localhost:3001",
changeOrigin: true,
secure: false,
},
"/logout": {
target: "http://localhost:3001",
changeOrigin: true,
secure: false,
},
},
},
});