From e38de4af4dd98705a226b551fa9d6729d7b1a130 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 22 Jun 2022 19:07:54 +0100 Subject: [PATCH] fix(vite): disable hmr in build (#5505) --- packages/vite/src/vite.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index 6b5925510c..6d57060c26 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -76,9 +76,7 @@ export async function bundle (nuxt: Nuxt) { reactivityTransform: nuxt.options.experimental.reactivityTransform }, server: { - watch: { - ignored: isIgnored - }, + watch: { ignored: isIgnored }, hmr: { // https://github.com/nuxt/framework/issues/4191 protocol: 'ws', @@ -96,6 +94,13 @@ export async function bundle (nuxt: Nuxt) { ) } + // In build mode we explicitly override any vite options that vite is relying on + // to detect whether to inject production or development code (such as HMR code) + if (!nuxt.options.dev) { + ctx.config.server.hmr = false + ctx.config.server.watch = undefined + } + await nuxt.callHook('vite:extend', ctx) nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => {