@isaacs/remix-hot-module-reload
Use this function when you want to reload your remix dev server's
modules when they change.
Designed to replace remix-run's default out of the box hot
module reloading, because it restarts on every request, which
thwarts debugging/testing memory caches, and never reloading
those things (by making them global) means that they won't ever
reload when the logic actually changes, either.
This only actually works with Remix, only tested on
remix-express, since that's what I use. It relies on the fact
that it can rebuild its request handler as needed.
If you find it useful as well, then that's lovely.
INSTALLATION
npm i @isaacs/hot-module-reload
USAGE
import { hotModuleReload } from '@isaacs/hot-module-reload'
if (NODE_ENV !== 'production') {
hotModuleReload({
filter: f => f.startsWith(BUILD_DIR),
frequency: 250,
callerRestart: () =>
new Promise(res => {
server.close(res)
server.closeAllConnections()
}),
callerModule: __filename,
})
}
app.all(
'*',
NODE_ENV === 'production'
? createRequestHandler({ build: require(BUILD_DIR) })
: (...args) =>
createRequestHandler({
build: require(BUILD_DIR),
})(...args)
)