import tailwindcss from '@tailwindcss/vite';
import adapter from '@sveltejs/adapter-auto';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig, type Plugin } from 'vite';
// Node closes a request whose body takes longer than 300 s (408), which cuts any long `git push` proxied to the sailfork server.
const unlimitedRequests = (): Plugin => {
const lift = (server: object | null) => {
if (server && 'requestTimeout' in server) server.requestTimeout = 0;
};
return {
name: 'unlimited-request-time',
configureServer: ({ httpServer }) => lift(httpServer),
configurePreviewServer: ({ httpServer }) => lift(httpServer)
};
};
const api = process.env.SAILFORK_API ?? 'http://127.0.0.1:7600';
export default defineConfig({
// Lets `tailscale serve` proxy the dev server on the tailnet's *.ts.net hostname.
server: {
host: '127.0.0.1',
allowedHosts: ['.ts.net'],
// A cold first request compiled the whole home page on demand (24s before HTML, ocean blank until hydration); compile it at startup instead.
warmup: {
clientFiles: ['./src/routes/+layout.svelte', './src/routes/+page.svelte'],
ssrFiles: ['./src/routes/+layout.svelte', './src/routes/+page.svelte']
},
// @sailfork/client is linked from outside the project, and its highlight worker is served from there.
fs: { allow: ['.', '../sailfork/client'] },
// One origin for the browser: the sailfork server answers the API, its sync WebSocket and git over HTTP.
proxy: {
'/api': { target: api, ws: true },
'^/[^/]+/[^/]+\\.git(/|$)': { target: api },
// `git clone sailfork::https://host/owner/repo` asks for these without the `.git`.
'^/[^/]+/[^/]+/sailfork/(clone|packs/)': { target: api }
}
},
plugins: [
tailwindcss(),
unlimitedRequests(),
sveltekit({
compilerOptions: {
// Force runes mode for the project, except for libraries. Can be removed in svelte 6.
runes: ({ filename }) =>
filename.split(/[/\\]/).includes('node_modules') ? undefined : true
},
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter(),
// The service worker serves one cached page for every app route, so its asset URLs must not depend on the page's depth.
paths: { relative: false }
})
]
});