You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

bundle-require

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bundle-require

bundle and require a file

npmnpm
Version
2.1.8
Version published
Weekly downloads
2.1M
-51.99%
Maintainers
1
Weekly downloads
 
Created
Source

💛 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

Sponsors

sponsors

License

MIT © EGOIST

FAQs

Package last updated on 25 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts