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.
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,
// 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.