From 65837fac2d2ae8e4abe0a4107b1394bb28f87089 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 21 Feb 2025 10:47:05 +1100 Subject: [PATCH 1/4] Ensure hot file is always an absolute path --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 45a3fe4..e18021d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -359,7 +359,7 @@ function resolvePluginConfig(config: string|string[]|PluginConfig): Required code), From 7b6a8e2d253b2485bfcf10d9a4966e46db1f9eb8 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 21 Feb 2025 10:49:00 +1100 Subject: [PATCH 2/4] Track changes to the dev server URL --- src/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/index.ts b/src/index.ts index e18021d..f3fe5b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -195,6 +195,15 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug configResolved(config) { resolvedConfig = config }, + async handleHotUpdate(update) { + if (update.file !== pluginConfig.hotFile) { + return + } + + const content = new Promise((resolve) => resolve(update.read())) + + viteDevServerUrl = (await content).trim() as DevServerUrl + }, transform(code) { if (resolvedConfig.command === 'serve') { code = code.replace(/http:\/\/__laravel_vite_placeholder__\.test/g, viteDevServerUrl) From 1665f6e0da2e70475011f643fd1fe1ac560f9eaf Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 21 Feb 2025 10:49:12 +1100 Subject: [PATCH 3/4] Force page reload on hot file changes --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index f3fe5b2..a79b8b8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -203,6 +203,8 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug const content = new Promise((resolve) => resolve(update.read())) viteDevServerUrl = (await content).trim() as DevServerUrl + + update.server.ws.send({ type: 'full-reload' }) }, transform(code) { if (resolvedConfig.command === 'serve') { From 135f70014137225c0368d9f2176e2f9391ffe414 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 21 Feb 2025 10:49:30 +1100 Subject: [PATCH 4/4] Log hot file changes --- src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index a79b8b8..119d365 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,10 +4,14 @@ import os from 'os' import { fileURLToPath } from 'url' import path from 'path' import colors from 'picocolors' -import { Plugin, loadEnv, UserConfig, ConfigEnv, ResolvedConfig, SSROptions, PluginOption } from 'vite' +import { Plugin, loadEnv, UserConfig, ConfigEnv, ResolvedConfig, SSROptions, PluginOption, createLogger } from 'vite' import fullReload, { Config as FullReloadConfig } from 'vite-plugin-full-reload' import { InputOption } from "rollup" +const logger = createLogger('info', { + prefix: '[laravel-vite-plugin]' +}) + interface PluginConfig { /** * The path or paths of the entry points to compile. @@ -205,6 +209,11 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug viteDevServerUrl = (await content).trim() as DevServerUrl update.server.ws.send({ type: 'full-reload' }) + + logger.info(`${colors.green('page reload')} Hot file changed ${colors.dim(viteDevServerUrl)}`, { + timestamp: true, + clear: true, + }) }, transform(code) { if (resolvedConfig.command === 'serve') {