UNPKG

glob-import-esbuild-plugin

Version:

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

54 lines (38 loc) 1.23 kB
# Description This esbuild plugin allows importing multiple modules by using a glob pattern. ## 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**: ```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](https://vitejs.dev/guide/features#glob-import). ## Usage **esbuild.config.js**: ```js import { build } from 'esbuild'; import globImportPlugin from "glob-import-esbuild-plugin"; await build({ ..., plugins: [globImportPlugin] }) ``` ## Prior art - Vite's glob import: https://vitejs.dev/guide/features#glob-import - [esbuild-plugin-import-glob](https://github.com/thomaschaaf/esbuild-plugin-import-glob): The import result is an array and doesn't work with named exports.