0.2.0 • Published 1 year ago
@abstract-money/bundle-require v0.2.0
@abstract-money/bundle-require
Disclaimer
This package is a fork of egoist/bundle-require version 3.1.2 with the corrected esbuild peer dependency as one breaks when used as peer in the projects that depend on the esbuild<0.17.0.
Use Case
Projects like Vite need to load config files provided by the user, but you can't do it with just require() because it's not necessarily a CommonJS module, it could also be a .mjs or even be written in TypeScript, and that's where the bundle-require package comes in, it loads the config file regardless what module format it is.
How it works
- Bundle your file with esbuild,
node_modulesare excluded because it's problematic to try to bundle it__filename,__dirnameandimport.meta.urlare replaced with source file's value instead of the one from the temporary output file
- Output file in
esmformat if possible (for.ts,.jsinput files) - Load output file with
import()if possible - Return the loaded module and its dependencies (imported files)
Install
npm i @abstract-money/bundle-require esbuildesbuild is a peer dependency.
Usage
import { bundleRequire } from '@abstract-money/bundle-require'
const { mod } = await bundleRequire({
filepath: './project/vite.config.ts',
})API
https://www.jsdocs.io/package/@abstract-money/bundle-require
Projects Using @abstract-money/bundle-require
Projects that use @abstract-money/bundle-require:
- VuePress: :memo: Minimalistic Vue-powered static site generator.
Sponsors
License
MIT © EGOIST