HMR
PluginHmrAPI — hook into dev-server file watching and send custom HMR events to connected clients.
ctx.hmr — PluginHmrAPI
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 also
- PluginContext — base context object
- Server — HTTP middleware & server lifecycle
- Middleware — transform middleware pipeline
- Lifecycle Hooks — build/dev hooks, transform chains, and chain signals
Last updated on October 18, 2026