A signed-in user with a snapshot goes straight to home; the same boot requests run in the background and replace it. Snapshot is cleared whenever tokens are cleared and on a new login, ignored from another build or when older than 7 days, and dropped when the fresh profile is a different user (reboot remounts MainApp via a generation key; AnimatePresence otherwise kept the exiting one). Notifications/characters wait for the profile answer so an expired access token costs the same requests as before. refreshHome applies only the latest answer. Home shows a "saved data" strip when the map could not be refreshed. Measured locally (old vs new build, same backend, Chrome throttling, median of 3, time to map): Fast 3G 2.46s -> 1.80s (expired token 3.63s -> 1.80s); Slow 3G 8.52s -> 6.14s (expired 12.6s -> 6.13s); API requests per open unchanged (6 valid, 11 expired). 12/12 behaviour checks passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import { defineConfig, loadEnv } from 'vite';
|
|
import path from 'node:path';
|
|
import react from '@vitejs/plugin-react';
|
|
import tailwindcss from '@tailwindcss/vite';
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), 'VITE_');
|
|
const proxyTarget = env.VITE_DEV_PROXY_TARGET || 'http://127.0.0.1:8000';
|
|
|
|
return {
|
|
plugins: [react(), tailwindcss()],
|
|
// عکسِ خانه (src/state/homeSnapshot.ts) فقط با همان بیلدی خوانده میشود که نوشتهاش؛ بعد از هر دیپلوی
|
|
// بارِ اول مثلِ قبل از سرور میآید، تا دادهای با شکلِ قدیمی به کدِ تازه نرسد.
|
|
define: { __APP_BUILD__: JSON.stringify(Date.now().toString(36)) },
|
|
resolve: {
|
|
alias: { '@': path.resolve(__dirname, './src') },
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
// pay.html: صفحهی واسطهی درگاه برای اپِ اندروید (src/pay.ts).
|
|
input: { main: path.resolve(__dirname, 'index.html'), pay: path.resolve(__dirname, 'pay.html') },
|
|
output: {
|
|
// کتابخانهها با هر انتشار عوض نمیشوند؛ فایلِ جدا یعنی بعد از هر دیپلوی
|
|
// از کشِ مرورگر میآیند و فقط کدِ خودِ اپ دوباره دانلود میشود.
|
|
manualChunks: {
|
|
react: ['react', 'react-dom'],
|
|
motion: ['motion/react'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
// در توسعه /api همدامنه است و به بکاند پاس داده میشود؛ CORS لازم نیست.
|
|
proxy: {
|
|
'/api': { target: proxyTarget, changeOrigin: true, secure: true },
|
|
},
|
|
},
|
|
};
|
|
});
|