/esbuild-plugin-glob

glob entry points in esbuild

Primary LanguageTypeScriptMIT LicenseMIT

⚡️ esbuild plugin glob ⚡️

Use glob entry points in esbuild.

This plugin allows the usage of glob patterns as entry points for esbuild. It supports single builds as well as watch mode.

Installation

Use a package manager like yarn or npm

yarn install esbuild-plugin-glob

Usage

import { globPlugin } from 'esbuild-plugin-glob';

esbuild.build({
  entryPoints: ['src/**/*.tsx'],
  // watch: true,
  plugins: [globPlugin()],
});

API and defaults

globPlugin({
  // Options directly passed to chokidar when in watch mode
  chokidarOptions: {}
  // Make the function return a `controls` object, see below
  controls: false
})

Controls

By passing the option controls: true the globPlugin function returns a tuple with the plugin object and a controls object.

import { globPlugin } from 'esbuild-plugin-glob';

const [glob, globControls] = globPlugin({ controls: true });

esbuild.build({
  entryPoints: ['src/**/*.tsx'],
  watch: true,
  plugins: [glob],
});

// Stops watching the entry files when in watch mode
await globControls.stopWatching();

How it works

For single builds it simply resolves the provided glob patterns before esbuild runs.

In watch mode it uses chokidar to watch the provided glob patterns and inspects the corresponding esbuild build results to make sure dependencies are also being watched.

Contribute

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT