From 29910e5faa23f012949333948904f19d4e1329e3 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Thu, 15 Feb 2024 23:09:37 +0900 Subject: [PATCH] feat: add `restart-on-add-unlink` vite plugin (#55) --- src/vite/index.ts | 2 ++ src/vite/restart-on-add-unlink.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/vite/restart-on-add-unlink.ts diff --git a/src/vite/index.ts b/src/vite/index.ts index 2318e86..64acbcc 100644 --- a/src/vite/index.ts +++ b/src/vite/index.ts @@ -4,6 +4,7 @@ import type { DevServerOptions } from '@hono/vite-dev-server' import type { PluginOption } from 'vite' import { injectImportingIslands } from './inject-importing-islands.js' import { islandComponents } from './island-components.js' +import { restartOnAddUnlink } from './restart-on-add-unlink.js' type Options = { islands?: boolean @@ -40,6 +41,7 @@ function honox(options?: Options): PluginOption[] { } plugins.push(injectImportingIslands()) + plugins.push(restartOnAddUnlink()) return [ { diff --git a/src/vite/restart-on-add-unlink.ts b/src/vite/restart-on-add-unlink.ts new file mode 100644 index 0000000..2ce7698 --- /dev/null +++ b/src/vite/restart-on-add-unlink.ts @@ -0,0 +1,16 @@ +import type { Plugin } from 'vite' + +export function restartOnAddUnlink(): Plugin { + return { + name: 'restart-on-add-unlink', + configureServer(server) { + server.watcher.add('/app/**') + server.watcher.on('add', async () => { + await server.restart() + }) + server.watcher.on('unlink', async () => { + await server.restart() + }) + }, + } +}