# esbuild-plugin-glob-import

> Use globs to import multiple files.

Latest version **0.2.0** (published 2022-06-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install esbuild-plugin-glob-import
pnpm add esbuild-plugin-glob-import
yarn add esbuild-plugin-glob-import
bun add esbuild-plugin-glob-import
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2022-06-04 |
| First published | 2022-06-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dustin Dowell |
| Maintainers | whaaaley |
| Keywords | esbuild, plugin, fast, glob, import |

## Links

- npm: https://www.npmjs.com/package/esbuild-plugin-glob-import
- npm.io page: https://npm.io/package/esbuild-plugin-glob-import

## Dependencies (1)

- [fast-glob](https://npm.io/package/fast-glob.md) ^3.2.11

## Recent versions

- 0.2.0 (latest) — 2022-06-04
- 0.1.1 — 2022-06-02
- 0.1.0 — 2022-06-02

## README

# esbuild-plugin-glob-import

Use globs to import multiple files.

## Install

```sh
$ npm i esbuild-plugin-glob-import
```

## Setup

Add the plugin to your esbuild options.

```js
import esbuild from 'esbuild'
import globImport from 'esbuild-plugin-glob-import'

esbuild.build({
  // ...
  plugins: [
    globImport()
  ]
})
```

## Options

+ `camelCase` - truthy or falsey - If truthy, this camel cases paths and filenames and removes file extensions.
+ `entryPoint` - string or falsey - Set which file in a directory is the entry point. If `entryPoint` is a string and matches a file, that module will be set on the key of the parent directory's name. If `entryPoint` is falsey all matching files will be imported and included in an object on keys of those file's names.
+ `entryPointMatch` - function or nullish - Determine which file in a directory is the entry point. This function is called for every file imported using a glob. It receives the filepath as an array. Return truthy if the path is an entry point and falsey if not.

## Example with default options

Options:

```js
const opts = {
  camelCase: true,
  entryPoint: 'index.js',
  entryPointMatch: arr => arr[arr.length - 1] === opts.entryPoint
}
```

File structure:

```
/pages
  /home
    home.css
    index.js
  /about
    /content
      summary.js
      history.js
    about.css
    index.js
  /error
    error.css
    index.js
```

Glob import statement:

```js
import pages from './pages/**/index.js'
console.log(pages)
```

Output:

```js
{
  home: function () {
    // ...
  },
  about: function () {
    // ...
  },
  error: function () {
    // ...
  }
}
```

## Alternative Example

Using the same file structure and import statement from the previous example but with different options.

Options:

```js
const opts = {
  camelCase: false,
  entryPoint: false,
  entryPointMatch: null
}
```

Output:

```js
{
  home: {
    'index.js': function () {
      // ...
    }
  },
  about: {
    'index.js': function () {
      // ...
    },
    content {
      'summary.js': function () {
        // ...
      },
      'history.js': function () {
        // ...
      }
    }
  },
  error: {
    'index.js': function () {
      // ...
    }
  }
}
```

## Prior Art

+ [esbuild](https://esbuild.github.io/)
+ [esbuild-plugin-import-glob](https://github.com/thomaschaaf/esbuild-plugin-import-glob)
+ [fast-glob](https://github.com/mrmlnc/fast-glob)

---
_Source: https://npm.io/package/esbuild-plugin-glob-import · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
