@@ -11,14 +11,16 @@ import { log } from './log';
11
11
import { loadSvelteConfig } from './load-svelte-config' ;
12
12
import { SVELTE_HMR_IMPORTS , SVELTE_IMPORTS , SVELTE_RESOLVE_MAIN_FIELDS } from './constants' ;
13
13
// 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 {
16
16
MarkupPreprocessor ,
17
17
Preprocessor ,
18
18
PreprocessorGroup ,
19
19
Processed
20
20
// eslint-disable-next-line node/no-missing-import
21
21
} from 'svelte/types/compiler/preprocess' ;
22
+ // eslint-disable-next-line node/no-missing-import
23
+ import type { KitConfig } from '@sveltejs/kit' ;
22
24
import path from 'path' ;
23
25
import { findRootSvelteDependencies , needsOptimization , SvelteDependency } from './dependencies' ;
24
26
import { createRequire } from 'module' ;
@@ -76,7 +78,6 @@ export async function preResolveOptions(
76
78
inlineOptions ,
77
79
extraOptions
78
80
) ;
79
-
80
81
// configFile of svelteConfig contains the absolute path it was loaded from,
81
82
// prefer it over the possibly relative inline path
82
83
if ( svelteConfig ?. configFile ) {
@@ -116,6 +117,7 @@ export function resolveOptions(
116
117
const merged : ResolvedOptions = mergeConfigs ( defaultOptions , preResolveOptions , extraOptions ) ;
117
118
118
119
removeIgnoredOptions ( merged ) ;
120
+ addSvelteKitOptions ( merged ) ;
119
121
addExtraPreprocessors ( merged , viteConfig ) ;
120
122
enforceOptionsForHmr ( merged ) ;
121
123
enforceOptionsForProduction ( merged ) ;
@@ -195,6 +197,23 @@ function removeIgnoredOptions(options: ResolvedOptions) {
195
197
}
196
198
}
197
199
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
+
198
217
// vite passes unresolved `root`option to config hook but we need the resolved value, so do it here
199
218
// https://github.com/sveltejs/vite-plugin-svelte/issues/113
200
219
// https://github.com/vitejs/vite/blob/43c957de8a99bb326afd732c962f42127b0a4d1e/packages/vite/src/node/config.ts#L293
@@ -476,6 +495,11 @@ export interface Options {
476
495
* These options are considered experimental and breaking changes to them can occur in any release
477
496
*/
478
497
experimental ?: ExperimentalOptions ;
498
+
499
+ /**
500
+ * Options for SvelteKit
501
+ */
502
+ kit ?: KitConfig ;
479
503
}
480
504
481
505
/**
0 commit comments