HMR

PluginHmrAPI — hook into dev-server file watching and send custom HMR events to connected clients.

ctx.hmr — PluginHmrAPILink

Hook into the dev-server file-watching pipeline and send custom events to connected browser clients.

ts
// Listen for file changes inside docs/
ctx.hmr.onFileChange(async (filePath) => {
  ctx.logger.info(`File modified: ${filePath}`)
})

// Listen for new files
ctx.hmr.onFileAdd((filePath) => {
  ctx.logger.info(`New document: ${filePath}`)
})

// Listen for file deletions
ctx.hmr.onFileUnlink((filePath) => {
  ctx.logger.info(`Document removed: ${filePath}`)
})

// Send a custom HMR event to all connected browser clients
ctx.hmr.send('my-plugin:update', { reason: 'regenerated' })
// Clients listen with: import.meta.hot.on('boltdocs:plugin:my-plugin:update', ...)

See alsoLink

Last updated on October 18, 2026

Was this page helpful?