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.
Esbuild now natively supports glob-style entrypoints since v0.19.0. This plugin is no longer needed.
Also note that this plugin is not yet compatible with esbuild v0.17.0 and up. It's a bit tricky to get it working with the new context
api (watch
mode in particular). If you'd like this functionality, please open an issue or a PR.
Use a package manager like yarn or npm
yarn add esbuild-plugin-glob
import { globPlugin } from 'esbuild-plugin-glob';
esbuild.build({
entryPoints: ['src/**/*.tsx'],
// watch: true,
plugins: [globPlugin()],
});
globPlugin({
// Optional additional entrypoints/glob patterns
additionalEntrypoints: [],
// Options directly passed to chokidar when in watch mode
chokidarOptions: {},
// Make the function return a `controls` object, see below
controls: false,
// An array of glob patterns to exclude matches
ignore: []
// Disables logging on file changes
silent: false,
})
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();
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.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.