import { fileURLToPath } from 'node:url'; import tailwindcss from '@tailwindcss/vite'; import react from '@vitejs/plugin-react'; import { defineConfig } from 'vite'; import { viteSingleFile } from 'vite-plugin-singlefile'; // One file out. The site record names each file by path, and the page HTML // caches for minutes, so a build split across hashed assets would leave a // visitor holding old HTML asking for a script the record no longer names. // A self-contained document cannot fall out of step with itself. // Where `npm run dev` sends the two routes the account's own site answers: // the DID the hostname publishes, and the blobs the pack reader opens. The // dev server has neither, and its SPA fallback would answer a blob request // with the page itself. const PDS_URL = process.env.PDS_URL || 'http://localhost:2471'; export default defineConfig({ plugins: [react(), tailwindcss(), viteSingleFile()], server: { // The dev server answers only the hosts it is told to, localhost by // default. A phone on the same tailnet reaches it by the machine's // tailnet name, which goes here. allowedHosts: process.env.VITE_ALLOWED_HOSTS ? process.env.VITE_ALLOWED_HOSTS.split(',') : undefined, proxy: { '/.well-known': PDS_URL, '/.blobs': PDS_URL, // The account pages the settings link opens are served from the // account's own site; the dev server is on a port of its own, so it // proxies them. '/account': PDS_URL, }, }, resolve: { alias: [ { find: /^#\/(.*)/, replacement: `${fileURLToPath(new URL('./src', import.meta.url))}/$1`, }, ], }, build: { target: 'es2022', assetsInlineLimit: 100000000, chunkSizeWarningLimit: 4096, cssCodeSplit: false, reportCompressedSize: false, }, });