130 lines
4.4 KiB
JavaScript
130 lines
4.4 KiB
JavaScript
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import tailwindcss from '@tailwindcss/vite';
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { createRequire } from 'module';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const require = createRequire(import.meta.url);
|
|
const pkg = require('./package.json');
|
|
const apiPort = process.env.API_PORT || process.env.PORT || 3000;
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
tailwindcss(),
|
|
// React Compiler (React 19): auto-memoizes components/hooks at build time, so
|
|
// manual useMemo/useCallback become largely unnecessary. Safe here because the
|
|
// codebase is rules-of-hooks clean (enforced by eslint-plugin-react-hooks).
|
|
react({
|
|
babel: {
|
|
plugins: [['babel-plugin-react-compiler', {}]],
|
|
},
|
|
}),
|
|
VitePWA({
|
|
registerType: 'autoUpdate',
|
|
includeAssets: [
|
|
'brand/favicon.svg',
|
|
'brand/favicon.ico',
|
|
'brand/mark.svg',
|
|
'brand/mark.png',
|
|
'brand/mark-mono.svg',
|
|
'brand/lockup.svg',
|
|
'brand/lockup-light.svg',
|
|
'brand/logo.png',
|
|
'brand/empty-state.svg',
|
|
'brand/social-preview.svg',
|
|
'brand/social-preview.png',
|
|
'img/auth.svg',
|
|
'brand/pwa-maskable.svg',
|
|
'brand/glyphs/tracker.svg',
|
|
'brand/glyphs/bills.svg',
|
|
'brand/glyphs/calendar.svg',
|
|
'brand/glyphs/analytics.svg',
|
|
'brand/glyphs/data-banking.svg',
|
|
'brand/glyphs/snowball-payoff.svg',
|
|
'brand/glyphs/admin-security.svg',
|
|
'brand/pwa-192.png',
|
|
'brand/pwa-512.png',
|
|
'brand/pwa-maskable-512.png',
|
|
],
|
|
manifest: {
|
|
name: 'Bill Tracker',
|
|
short_name: 'Bill Tracker',
|
|
description: 'Personal bill planning and tracking',
|
|
theme_color: '#101417',
|
|
background_color: '#101417',
|
|
display: 'standalone',
|
|
start_url: '/',
|
|
icons: [
|
|
{ src: '/brand/pwa-192.png', sizes: '192x192', type: 'image/png' },
|
|
{ src: '/brand/pwa-512.png', sizes: '512x512', type: 'image/png', purpose: 'any' },
|
|
{
|
|
src: '/brand/pwa-maskable-512.png',
|
|
sizes: '512x512',
|
|
type: 'image/png',
|
|
purpose: 'maskable',
|
|
},
|
|
],
|
|
},
|
|
workbox: {
|
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'],
|
|
runtimeCaching: [
|
|
{
|
|
urlPattern: /^\/api\/(tracker|bills|calendar|summary|analytics|snowball|categories)/,
|
|
handler: 'NetworkFirst',
|
|
options: {
|
|
cacheName: 'api-cache',
|
|
networkTimeoutSeconds: 5,
|
|
expiration: { maxEntries: 30, maxAgeSeconds: 300 },
|
|
},
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
publicDir: 'client/public',
|
|
define: {
|
|
// Injected at build time — frontend reads this instead of maintaining a
|
|
// duplicate version string in client/lib/version.js
|
|
__APP_VERSION__: JSON.stringify(pkg.version),
|
|
},
|
|
resolve: {
|
|
alias: { '@': path.resolve(__dirname, './client') },
|
|
},
|
|
server: {
|
|
port: 5173,
|
|
proxy: {
|
|
'/api': { target: `http://localhost:${apiPort}`, changeOrigin: true },
|
|
},
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
emptyOutDir: true,
|
|
rollupOptions: {
|
|
output: {
|
|
// QA-B0-01: split the shared vendor code out of the ~659 kB index chunk
|
|
// so large libs load/cache independently and the main bundle shrinks.
|
|
// Function form: vite 8 (rolldown core) dropped the object form.
|
|
manualChunks(id) {
|
|
if (!id.includes('node_modules')) return undefined;
|
|
if (/node_modules[\\/](react|react-dom|react-router|react-router-dom)[\\/]/.test(id))
|
|
return 'vendor-react';
|
|
if (/node_modules[\\/]@radix-ui[\\/]/.test(id)) return 'vendor-radix';
|
|
if (/node_modules[\\/]framer-motion[\\/]/.test(id)) return 'vendor-motion';
|
|
if (/node_modules[\\/]@tanstack[\\/]/.test(id)) return 'vendor-query';
|
|
return undefined;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
// Vitest — client-side unit tests (pure logic in client/lib).
|
|
// Server tests stay on node:test (`npm run test`); client tests run with
|
|
// `npm run test:client`; `npm run test:all` runs both.
|
|
test: {
|
|
environment: 'node', // hook/component tests opt into jsdom via @vitest-environment
|
|
include: ['client/**/*.test.{js,jsx,ts,tsx}'],
|
|
},
|
|
});
|