@@ -201,7 +201,11 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
201
201
compilerOptions : {
202
202
css,
203
203
dev : ! viteConfig . isProduction ,
204
- hmr : ! viteConfig . isProduction && ! preResolveOptions . isBuild
204
+ hmr :
205
+ ! viteConfig . isProduction &&
206
+ ! preResolveOptions . isBuild &&
207
+ viteConfig . server &&
208
+ viteConfig . server . hmr !== false
205
209
}
206
210
} ;
207
211
@@ -217,7 +221,7 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
217
221
removeIgnoredOptions ( merged ) ;
218
222
handleDeprecatedOptions ( merged ) ;
219
223
addExtraPreprocessors ( merged , viteConfig ) ;
220
- enforceOptionsForHmr ( merged ) ;
224
+ enforceOptionsForHmr ( merged , viteConfig ) ;
221
225
enforceOptionsForProduction ( merged ) ;
222
226
// mergeConfigs would mangle functions on the stats class, so do this afterwards
223
227
if ( log . debug . enabled && isDebugNamespaceEnabled ( 'stats' ) ) {
@@ -228,15 +232,22 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
228
232
229
233
/**
230
234
* @param {import('../types/options.d.ts').ResolvedOptions } options
235
+ * @param {import('vite').ResolvedConfig } viteConfig
231
236
*/
232
- function enforceOptionsForHmr ( options ) {
237
+ function enforceOptionsForHmr ( options , viteConfig ) {
233
238
if ( options . hot ) {
234
239
log . warn (
235
240
'svelte 5 has hmr integrated in core. Please remove the vitePlugin.hot option and use compilerOptions.hmr instead'
236
241
) ;
237
242
delete options . hot ;
238
243
options . compilerOptions . hmr = true ;
239
244
}
245
+ if ( options . compilerOptions . hmr && viteConfig . server ?. hmr === false ) {
246
+ log . warn (
247
+ 'vite config server.hmr is false but compilerOptions.hmr is true. Forcing compilerOptions.hmr to false as it would not work.'
248
+ ) ;
249
+ options . compilerOptions . hmr = false ;
250
+ }
240
251
}
241
252
242
253
/**
@@ -264,7 +275,7 @@ function enforceOptionsForProduction(options) {
264
275
*/
265
276
function removeIgnoredOptions ( options ) {
266
277
const ignoredCompilerOptions = [ 'generate' , 'format' , 'filename' ] ;
267
- if ( options . hot && options . emitCss ) {
278
+ if ( options . compilerOptions . hmr && options . emitCss ) {
268
279
ignoredCompilerOptions . push ( 'cssHash' ) ;
269
280
}
270
281
const passedCompilerOptions = Object . keys ( options . compilerOptions || { } ) ;
0 commit comments