Node.js developer conveniences geared towards web dev
- Use Module reloading (HMR) hooks in Node.js's native module system
- Use JSX module transpilation hooks in Node.js's native module system
- Use FileTree to load a file tree from disk into memory
- Use DevServer to serve an in-memory file tree
- Use generateFiles to write an in-memory file tree to disk
- Use Pipeline to conveniently transform an in-memory file tree
import { FileTree, hooks } from 'immaculata'
import { registerHooks } from 'module'
// keep an in-memory version of file tree under "./src"
const tree = new FileTree('src', import.meta.dirname)
// load modules under "src" from memory
// and add query string to load latest version
registerHooks(tree.moduleHooks())
// keep tree up to date
// and re-import main module when any file changes
tree.watch().on('filesUpdated', doStuff)
doStuff()
// importing modules under 'src' now re-executes them
async function doStuff() {
const { stuff } = await import("src/dostuff.js")
// "stuff" is never stale
}
import { hooks } from 'immaculata'
import { registerHooks } from 'module'
// compile jsx using something like swc or tsc
registerHooks(hooks.compileJsx(compileJsxSomehow))
// remap "react-jsx/runtime" to any import you want (optional)
registerHooks(hooks.mapImport('react/jsx-runtime', 'immaculata/jsx-strings.js'))
// you can now import tsx files!
const { template } = await import('./site/template.tsx')