esbuild-plugin-wildcard-imports

raw JSON →
0.0.15 verified Fri May 01 auth: no javascript

esbuild plugin enabling wildcard/glob imports for dynamic imports, import statements, and require calls. Version 0.0.15, limited to platform=node and bundle=true. Uses fast-glob as matching engine. Supports both CJS and ESM output formats but primarily tested on CJS. Ignores node_modules by default and supports custom ignore patterns. A lightweight alternative to TypeScript path mapping or manual file listing.

error Error: The plugin "esbuild-plugin-wildcard-imports" only works with platform=node and bundle=true
cause Missing or incorrect esbuild config options.
fix
Add platform: 'node' and bundle: true to esbuild build options.
error Error: Dynamic import with top-level await not supported in CJS format
cause Using dynamic import with top-level await while format is cjs.
fix
Change format to esm or avoid top-level await in dynamically imported files.
error TypeError: wildcardImports is not a function
cause Importing the default export incorrectly (e.g., using namespace import).
fix
Use import wildcardImports from 'esbuild-plugin-wildcard-imports'
breaking Only works with platform=node and bundle=true. Other configurations may cause build failures.
fix Ensure esbuild options include platform: 'node' and bundle: true.
deprecated Dynamic imports with top-level await will not work with format=cjs.
fix Use format=esm or avoid top-level await in dynamically imported modules.
gotcha node_modules are always ignored regardless of ignore patterns.
fix Do not attempt to include node_modules in glob patterns; they are excluded by design.
gotcha Only supports dynamic-import, import-statement, and require-call path types.
fix If you need other path types, the plugin will not resolve glob patterns.
npm install esbuild-plugin-wildcard-imports
yarn add esbuild-plugin-wildcard-imports
pnpm add esbuild-plugin-wildcard-imports

Configures esbuild with wildcard imports plugin, bundling for Node.js with CJS output. The plugin resolves glob patterns in import paths.

import * as esbuild from 'esbuild';
import wildcardImports from 'esbuild-plugin-wildcard-imports';

// Build with wildcard imports support
await esbuild.build({
  entryPoints: ['src/index.js'],
  bundle: true,
  platform: 'node',
  format: 'cjs',
  outfile: 'dist/index.js',
  plugins: [wildcardImports({
    ignore: ['**/node_modules/**']
  })]
});

// Example usage in source:
// import { endpoints } from './endpoints/**/*.js';