Skip to content

Commit

Permalink
feat: add restart-on-add-unlink vite plugin (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Feb 15, 2024
1 parent ad4c72d commit 29910e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,6 +41,7 @@ function honox(options?: Options): PluginOption[] {
}

plugins.push(injectImportingIslands())
plugins.push(restartOnAddUnlink())

return [
{
Expand Down
16 changes: 16 additions & 0 deletions src/vite/restart-on-add-unlink.ts
Original file line number Diff line number Diff line change
@@ -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()
})
},
}
}

0 comments on commit 29910e5

Please sign in to comment.