Skip to content

A esbuild plugin to import multiple modules using a glob pattern.

License

Notifications You must be signed in to change notification settings

Simonpedro/glob-import-esbuild-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This esbuild plugin allows importing multiple modules by using a glob pattern.

Installation

npm install glob-import-esbuild-plugin or yarn add glob-import-esbuild-plugin

Example

Given a project with the following structure:

index.js
a-folder/
├── module-a.js
└── a-subfolder/
    ├── module-b.js
    └── module-c.js

index.js:

import modules from "./a-folder/**/*.js"

console.log(modules)

// It'd print the following.
//
// {
//   "Users/jhondoe/example/a-folder/module-a.js": { aNamedExport, default},
//   "Users/jhondoe/example/a-folder/a-subfolder/module-b.js": { aNamedExport, default},
//   "Users/jhondoe/example/a-folder/a-subfolder/module-c.js": { aNamedExport, default},
// }

The import result is inspired (although not identical) to Vite's glob import.

Usage

esbuild.config.js:

import { build } from 'esbuild';
import globImportPlugin from "glob-import-esbuild-plugin";

await build({
  ...,
  plugins: [globImportPlugin]
})

Prior art

About

A esbuild plugin to import multiple modules using a glob pattern.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published