esbuild-plugin-import-glob

raw JSON →
0.1.1 verified Mon Apr 27 auth: no javascript

A esbuild plugin that enables glob pattern imports, allowing developers to import multiple files using syntax like './migrations/**/*'. Current stable version is 0.1.1. It has no active development cadence (last release likely 2021). Key differentiator: simple integration with esbuild, supports ESM and CJS import styles, returns an array of module exports along with filenames. Lightweight and zero-config.

error Error: The plugin 'esbuild-plugin-import-glob' is not compatible with esbuild version X.X.X
cause Plugin may depend on esbuild internals that change between versions.
fix
Check plugin's peerDependencies and use a compatible esbuild version.
error TypeError: Cannot read properties of undefined (reading 'default')
cause Accessing default export from import * as X when module has no default export.
fix
Ensure each matched file has a default export, or use namespace import and access properties directly.
gotcha TypeScript will complain about glob import paths with @ts-ignore.
fix Add // @ts-ignore above each glob import statement.
gotcha Plugin version 0.1.1 is very early; API may break without major version bump.
fix Pin to exact version and test updates thoroughly.
breaking Glob patterns are resolved at build time; dynamic imports with variables are not supported.
fix Use a literal string for the glob pattern.
npm install esbuild-plugin-import-glob
yarn add esbuild-plugin-import-glob
pnpm add esbuild-plugin-import-glob

Shows how to set up the plugin in an esbuild build script and use glob imports in source files.

// esbuild script
const esbuild = require('esbuild');
const ImportGlobPlugin = require('esbuild-plugin-import-glob');

esbuild.build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outfile: 'out.js',
  plugins: [
    ImportGlobPlugin(),
  ],
}).catch(() => process.exit(1));

// usage in source file (e.g., src/index.ts)
// @ts-ignore
import migrationsArray from './migrations/**/*';

console.log(migrationsArray); // array of module default exports

// @ts-ignore
import * as migrations from './migrations/**/*';

console.log(migrations.default); // same as above
console.log(migrations.filenames); // file paths