import tailwindcss from '@tailwindcss/vite';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { fileURLToPath } from 'node:url';

export default defineConfig({
	plugins: [tailwindcss(), sveltekit()],
	resolve: {
		alias: {
			// Deliberately a Vite-only alias, and deliberately not in kit.alias or
			// tsconfig paths. TypeScript cannot resolve `$foliate/*`, so the ambient
			// declaration in src/lib/reader/foliate.d.ts is the only candidate and
			// svelte-check never walks the ~11k lines of untyped vendored JS.
			$foliate: fileURLToPath(new URL('./src/lib/vendor/foliate-js', import.meta.url))
		}
	},
	optimizeDeps: {
		// Behind a dynamic import in foliate's fixed-layout.js, so Vite would
		// otherwise discover it mid-session and force a full page reload the first
		// time someone opens a fixed-layout EPUB.
		include: ['construct-style-sheets-polyfill']
	}
});
