@@ -11,14 +11,16 @@ import { log } from './log';
1111import { loadSvelteConfig } from './load-svelte-config' ;
1212import { SVELTE_HMR_IMPORTS , SVELTE_IMPORTS , SVELTE_RESOLVE_MAIN_FIELDS } from './constants' ;
1313// eslint-disable-next-line node/no-missing-import
14- import { CompileOptions , Warning } from 'svelte/types/compiler/interfaces' ;
15- import {
14+ import type { CompileOptions , Warning } from 'svelte/types/compiler/interfaces' ;
15+ import type {
1616 MarkupPreprocessor ,
1717 Preprocessor ,
1818 PreprocessorGroup ,
1919 Processed
2020 // eslint-disable-next-line node/no-missing-import
2121} from 'svelte/types/compiler/preprocess' ;
22+ // eslint-disable-next-line node/no-missing-import
23+ import type { KitConfig } from '@sveltejs/kit' ;
2224import path from 'path' ;
2325import { findRootSvelteDependencies , needsOptimization , SvelteDependency } from './dependencies' ;
2426import { createRequire } from 'module' ;
@@ -76,7 +78,6 @@ export async function preResolveOptions(
7678 inlineOptions ,
7779 extraOptions
7880 ) ;
79-
8081 // configFile of svelteConfig contains the absolute path it was loaded from,
8182 // prefer it over the possibly relative inline path
8283 if ( svelteConfig ?. configFile ) {
@@ -116,6 +117,7 @@ export function resolveOptions(
116117 const merged : ResolvedOptions = mergeConfigs ( defaultOptions , preResolveOptions , extraOptions ) ;
117118
118119 removeIgnoredOptions ( merged ) ;
120+ addSvelteKitOptions ( merged ) ;
119121 addExtraPreprocessors ( merged , viteConfig ) ;
120122 enforceOptionsForHmr ( merged ) ;
121123 enforceOptionsForProduction ( merged ) ;
@@ -195,6 +197,23 @@ function removeIgnoredOptions(options: ResolvedOptions) {
195197 }
196198}
197199
200+ // some SvelteKit options need compilerOptions to work, so set them here.
201+ function addSvelteKitOptions ( options : ResolvedOptions ) {
202+ if ( options ?. kit != null ) {
203+ const hydratable = options . kit . browser ?. hydrate !== false ;
204+ if (
205+ options . compilerOptions . hydratable != null &&
206+ options . compilerOptions . hydratable !== hydratable
207+ ) {
208+ log . warn (
209+ `Conflicting values "compilerOptions.hydratable: ${ options . compilerOptions . hydratable } " and "kit.browser.hydrate: ${ options . kit . browser ?. hydrate } " in your svelte config. You should remove "compilerOptions.hydratable".`
210+ ) ;
211+ }
212+ log . debug ( `Setting compilerOptions.hydratable: ${ hydratable } for SvelteKit` ) ;
213+ options . compilerOptions . hydratable = hydratable ;
214+ }
215+ }
216+
198217// vite passes unresolved `root`option to config hook but we need the resolved value, so do it here
199218// https://github.com/sveltejs/vite-plugin-svelte/issues/113
200219// https://github.com/vitejs/vite/blob/43c957de8a99bb326afd732c962f42127b0a4d1e/packages/vite/src/node/config.ts#L293
@@ -476,6 +495,11 @@ export interface Options {
476495 * These options are considered experimental and breaking changes to them can occur in any release
477496 */
478497 experimental ?: ExperimentalOptions ;
498+
499+ /**
500+ * Options for SvelteKit
501+ */
502+ kit ?: KitConfig ;
479503}
480504
481505/**
0 commit comments