From 568e178a10768211944bfc1aaf6e57a6a091693d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A2=EF=BD=85=EF=BD=8E=E2=80=83=EF=BC=B4=EF=BD=85?= =?UTF-8?q?=EF=BD=81?= <66273043+benatshippabo@users.noreply.github.com> Date: Sat, 3 Jun 2023 17:23:27 -0700 Subject: [PATCH] fix(hmr): fix hmr when using h2 and use merge config (#110) * fix hmr when using h2 and use merge config * flip order --- packages/fastify-vite/mode/development.js | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/fastify-vite/mode/development.js b/packages/fastify-vite/mode/development.js index b8148f1f..88429494 100644 --- a/packages/fastify-vite/mode/development.js +++ b/packages/fastify-vite/mode/development.js @@ -1,4 +1,5 @@ const middie = require('@fastify/middie') +const { mergeConfig, defineConfig } = require('vite') const { join, resolve, read } = require('../ioutils') async function setup (config) { @@ -7,15 +8,20 @@ async function setup (config) { await this.scope.register(middie) // Create and enable Vite's Dev Server middleware - const devServerOptions = { - configFile: false, - ...config.vite, - server: { - middlewareMode: true, - ...config.vite.server - }, - appType: 'custom' - } + const devServerOptions = mergeConfig( + defineConfig({ + configFile: false, + server: { + middlewareMode: true, + hmr: { + server: this.scope.server + } + }, + appType: 'custom' + }), + config.vite + ) + const { createServer } = require('vite') this.devServer = await createServer(devServerOptions) this.scope.use(this.devServer.middlewares)