RestroAi/vite.config.ts

87 lines
2.3 KiB
TypeScript

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { VitePWA } from 'vite-plugin-pwa';
import path from 'node:path';
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.svg', 'icons.svg'],
manifest: {
name: 'RestroAI Guest',
short_name: 'RestroAI',
description: 'Scan, order, and pay at your table',
theme_color: '#ac2d00',
background_color: '#fff9f7',
display: 'standalone',
start_url: '/',
scope: '/',
icons: [
{
src: '/icons.svg',
sizes: 'any',
type: 'image/svg+xml',
purpose: 'any maskable',
},
],
},
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,webp,woff2}'],
navigateFallback: '/index.html',
navigateFallbackDenylist: [/^\/staff\.html/, /^\/api/],
runtimeCaching: [
{
urlPattern: ({ url }) => url.pathname.includes('/menu/public'),
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'restroai-menu',
expiration: {
maxEntries: 20,
maxAgeSeconds: 60 * 60 * 24,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: ({ request }) => request.destination === 'image',
handler: 'CacheFirst',
options: {
cacheName: 'restroai-images',
expiration: {
maxEntries: 60,
maxAgeSeconds: 60 * 60 * 24 * 7,
},
},
},
],
},
// Dev uses Vite HMR; SW/precache only in production builds (avoids empty dev-dist warning).
devOptions: {
enabled: false,
},
}),
],
resolve: {
alias: {
'@restroai/ui': path.resolve(__dirname, 'packages/ui/src'),
},
},
build: {
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
staff: path.resolve(__dirname, 'staff.html'),
},
},
},
server: {
host: '0.0.0.0',
port: 5173,
},
});