Files
when/apps/web/vite.config.ts
eleith 328f8ab0d1
ci/woodpecker/pr/web Pipeline was successful
ci/woodpecker/push/web Pipeline was successful
perf(web): inline initial booking styles
2026-11-02 15:29:39 -08:00

67 lines
2.0 KiB
TypeScript

import adapter from '@sveltejs/adapter-node';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
import Icons from 'unplugin-icons/vite';
// Dev-server host allowlist (Vite dev/preview only — prod runs adapter-node).
// localhost and IPs are always allowed by Vite; the dev environment declares any
// extra hosts (e.g. the docker service name the worker uses to reach web).
const allowedHosts = (process.env.WHEN_ALLOWED_HOSTS ?? '')
.split(',')
.map((host) => host.trim())
.filter(Boolean);
export default defineConfig(({ command }) => {
// Dev server only (not `vite build`, not vitest): run @when/* from source.
const sourceFirst = command === 'serve' && !process.env.VITEST;
return {
plugins: [
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: adapter(),
// Include the booking wizard's CSS in the initial HTML, avoiding a blocking request.
inlineStyleThreshold: 32 * 1024,
csp: {
directives: {
'default-src': ['self'],
'script-src': ['self'],
// The theme <style> is injected after Kit has hashed the page.
'style-src': ['self', 'unsafe-inline'],
'img-src': ['self', 'data:'],
'font-src': ['self'],
'connect-src': ['self'],
'object-src': ['none'],
'base-uri': ['self'],
'form-action': ['self', 'https://accounts.google.com'],
'frame-ancestors': ['none']
}
}
}),
Icons({ compiler: 'svelte' })
],
server: {
allowedHosts
},
// noExternal makes Vite transform the packages' TS rather than hand it to Node.
ssr: sourceFirst ? { noExternal: [/^@when\//] } : {},
test: {
include: ['src/**/*.test.ts'],
environment: 'node',
coverage: {
include: ['src/**/*.ts'],
thresholds: {
statements: 70,
branches: 68,
functions: 72,
lines: 70
}
}
}
};
});