Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bundle-import

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bundle-import

Bundle and load a file using the import-from-string.

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Bundle-import

NPM version Downloads License GitHub stars

Bundle and load a file using the import-from-string.

Difference from bundle-require

Most of the code of Bundle-import comes from bundle-require. There is no objection to this, but Bundle-import does not generate temporary files when reading module contents, which can avoid conflicts with other tools. For example, the following two issues:

  1. Tmp .mjs file in the current directory breaks other tools
  2. vite 运行时,修改mock文件会生成很多个xxx.mjs文件

Features

  • Support ESM and CJS environments
  • Support dynamic import
  • Support import.meta.url
  • Support access to global variables
  • No asynchronous IO operations
  • No module cache

Install

npm install bundle-import

Usage

ESM

import { bundleImport } from "bundle-import";

const { mod: mod1 } = await bundleImport({ filepath: "./fixtures/index.cjs", cwd: `${process.cwd()}/playground` });
console.log(mod1);

const { mod: mod2 } = await bundleImport({ filepath: "./playground/fixtures/index.mjs" });
console.log(mod2.default, mod2);

CJS

const { bundleImport } = require("bundle-import");

async function main() {
	const { mod: mod1 } = await bundleImport({ filepath: "./fixtures/index.cjs", cwd: `${process.cwd()}/playground` });
	console.log(mod1);

	const { mod: mod2 } = await bundleImport({ filepath: "./playground/fixtures/index.mjs" });
	console.log(mod2.default, mod2);
}

main();

API

bundleImport(options)

options
cwd

Type: string
Default: process.cwd()

Project root directory.

filename

Type: string
Required: true

The filepath to bundle and require.

external

Type: (string | RegExp)[]
Required: []

External packages.

tsconfig

Type: string
Required: tsconfig.json

A custom tsconfig path to read paths option.

format

Type: "cjs" | "esm"\

Provide bundle format explicitly to skip the default format inference.

esbuildOptions

Type: BuildOptions
Required: false

esbuild options.

Appreciation

License

MIT License © 2023-Present Condor Hero

Keywords

FAQs

Package last updated on 06 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc