@boost/module
Load and resolve custom file types at runtime with a more powerful Node.js require
replacement.
import { requireModule } from '@boost/module';
const result = requireModule('./some/non-js/file.ts');
Or with next-generation loaders.
node --experimental-loader @boost/module/loader.mjs ./path/to/entry-point.mjs
Features
- CommonJS based importing with
requireModule()
- CommonJS interoperability with ESM-like files
- ECMAScript module based importing with a custom ESM loader
- Supported file types: TypeScript (
.ts
,.tsx
)
Installation
yarn add @boost/module
Documentation
Index
Type Aliases
LoaderDefaultLoad
LoaderDefaultResolve
LoaderLoad
LoaderResolve
ModuleLike
Type parameters
- D = unknown
- N: object = {}
Return shape of a module. The default export can be typed with the
D
generic slot, and the named exports can be typed with an object in theN
generic slot.If there is no default export (classic Node.js
exports
pattern), thenvoid
can be passed to theD
generic, which will populate thedefault
property with the named exports.