bundle-require
bundle and require a file
Last updated 3 years ago by egoist .
MIT · Original npm · Tarball · package.json
$ npm install bundle-require 
SYNC missed versions from official npm registry.

💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.


bundle-require

npm version npm downloads jsDocs.io

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_modules are excluded because it's problematic to try to bundle it
    • __filename, __dirname and import.meta.url are replaced with source file's value instead of the one from the temporary output file
  • Output file in esm format if possible (for .ts, .js input files)
  • Load output file with import() if possible
  • Return the loaded module and its dependencies (imported files)

Install

npm i bundle-require esbuild

esbuild is a peer dependency.

Usage

import { bundleRequire } from 'bundle-require'

const { mod } = await bundleRequire({
  filepath: './project/vite.config.ts',
})

API

https://www.jsdocs.io/package/bundle-require

Projects Using bundle-require

Projects that use bundle-require:

  • VuePress: :memo: Minimalistic Vue-powered static site generator.

Sponsors

sponsors

License

MIT © EGOIST

Current Tags

  • 5.0.0                                ...           latest (5 months ago)

42 Versions

  • 5.0.0                                ...           5 months ago
  • 4.2.1                                ...           5 months ago
  • 4.2.0                                ...           5 months ago
  • 4.1.0                                ...           6 months ago
  • 4.0.4                                ...           6 months ago
  • 4.0.3                                ...           7 months ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           2 years ago
  • 4.0.0                                ...           2 years ago
  • 3.1.2                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.5                                ...           2 years ago
  • 3.0.4                                ...           3 years ago
  • 3.0.3                                ...           3 years ago
  • 3.0.2                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.0                                ...           3 years ago
  • 2.1.8                                ...           3 years ago
  • 2.1.7                                ...           3 years ago
  • 2.1.6                                ...           3 years ago
  • 2.1.5                                ...           3 years ago
  • 2.1.4                                ...           3 years ago
  • 2.1.3                                ...           3 years ago
  • 2.1.2                                ...           3 years ago
  • 2.1.1                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 1.4.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.4.0 [deprecated]           ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Total 37
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (7)
Dependents (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE