4 ms·
Oh no, I must have mis-explained it. The file `site/myfile.js` does exist. All FileTree does is recursively load all files in a dir into memory. The `useTree`
by sbjs 1y ago
Oh no, I must have mis-explained it.
The file `site/myfile.js` does exist. All FileTree does is recursively load all files in a dir into memory.
The `useTree` module hook does two things:
* Pulls the file from memory when loading it instead of from disk
* Adds a cache busting query string when resolving it for invalidation
Combined with tree.watch(), this essentially allows you to add a very lightweight but extremely accurate hot module replacement system into Node.js
const tree = new FileTree('src', import.meta.url)
registerHooks(useTree(tree))
tree.watch().on('filesUpdated', () => import(tree.root + '/myfile.js'))
import(tree.root + '/myfile.js')
Now save src/myfile.js and see it re-executed