The pear-hotmods
library is a Pear ecosystem library.
It automatically reloads Module instances which can be passed on to a live-reload mechanism commonly supplied by frontend-frameworks.
npm install pear-hotmods
const { hotmods } = await import('pear-hotmods')
import hotmods from 'pear-hotmods'
Call the listener
function
Options
paths
<Array>
- paths allowlist to match against. Paths are drive keys: they are rooted to application root. If unset or empty array, matches against all paths.
Scenario where Preact framework is being used with prefresh for hot-reloading during application development:
if (Pear.config.dev) {
const { hotmods } = await import('pear-hotmods')
await import('@prefresh/core')
hotmods({ paths: ['/components'] }, (reloads) => {
for (const { original, previous, next, type, key } of reloads) {
console.log('Hot reloading - path:', key, 'operation:', type)
window.__PREFRESH__.replaceComponent(original, next, true)
window.__PREFRESH__.replaceComponent(previous, next, true)
}
})
}
Apache-2.0