8000 GitHub - sdegutis/immaculata: TypeScript DX primitives
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sdegutis/immaculata

Repository files navigation

Immaculata

Node.js developer conveniences geared towards web dev

Module HMR in Node.js

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
}

Native JSX in Node.jS

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')

About

TypeScript DX primitives

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0