diff --git a/docs/guide/api-environment-runtimes.md b/docs/guide/api-environment-runtimes.md index 787875977de46d..6a3858b24112f4 100644 --- a/docs/guide/api-environment-runtimes.md +++ b/docs/guide/api-environment-runtimes.md @@ -190,15 +190,10 @@ export interface ModuleRunnerOptions { | InterceptorOptions /** * Disable HMR or configure HMR options. + * + * @default true */ - hmr?: - | false - | { - /** - * Configure HMR logger. - */ - logger?: false | HMRLogger - } + hmr?: boolean | ModuleRunnerHmr /** * Custom module cache. If not provided, it creates a separate module * cache for each module runner instance. @@ -356,6 +351,7 @@ export const runner = new ModuleRunner( return response.json() }, }, + hmr: false, // disable HMR as HMR requires transport.connect }, new ESModulesEvaluator(), ) diff --git a/packages/vite/rollup.config.ts b/packages/vite/rollup.config.ts index 1cf3015f15d52f..5727cb537a046c 100644 --- a/packages/vite/rollup.config.ts +++ b/packages/vite/rollup.config.ts @@ -194,7 +194,7 @@ const moduleRunnerConfig = defineConfig({ ], plugins: [ ...createSharedNodePlugins({ esbuildOptions: { minifySyntax: true } }), - bundleSizeLimit(53), + bundleSizeLimit(54), ], }) diff --git a/packages/vite/src/module-runner/runner.ts b/packages/vite/src/module-runner/runner.ts index 5f103753f2e8fa..48942fae5c9964 100644 --- a/packages/vite/src/module-runner/runner.ts +++ b/packages/vite/src/module-runner/runner.ts @@ -69,13 +69,14 @@ export class ModuleRunner { this.root = root[root.length - 1] === '/' ? root : `${root}/` this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules() this.transport = normalizeModuleRunnerTransport(options.transport) - if (options.hmr) { + if (options.hmr !== false) { + const optionsHmr = options.hmr ?? true const resolvedHmrLogger: HMRLogger = - options.hmr === true || options.hmr.logger === undefined + optionsHmr === true || optionsHmr.logger === undefined ? hmrLogger - : options.hmr.logger === false + : optionsHmr.logger === false ? silentConsole - : options.hmr.logger + : optionsHmr.logger this.hmrClient = new HMRClient( resolvedHmrLogger, this.transport, diff --git a/packages/vite/src/module-runner/types.ts b/packages/vite/src/module-runner/types.ts index d880fa7a80accc..dbd769f26f9512 100644 --- a/packages/vite/src/module-runner/types.ts +++ b/packages/vite/src/module-runner/types.ts @@ -103,6 +103,8 @@ export interface ModuleRunnerOptions { | InterceptorOptions /** * Disable HMR or configure HMR options. + * + * @default true */ hmr?: boolean | ModuleRunnerHmr /**