esbuild-multicontext
Minimal wrapper over esbuild's context API
What and Why ?
When working with modern codebases, there's always more than one esbuild config
in place for either bundling server separately or the client separately and
managing mulitple esbuild instances isn't recommended. esbuild
provides a
context
API for long running esbuild tasks like watching and serving client
bundles. This package wraps the context API with a very tiny wrapper to make it
easier to write build tooling scripts without having to manage esbuild
instances.
Usage
import { createContext, CONSTANTS } from 'esbuild-multicontext'
const buildContext = createContext()
const entries = await buildContext.glob('./src/*.js', {
filesOnly: true,
})
buildContext.add('esm', {
entryPoints: entries,
outdir: './dist/esm',
format: 'esm',
outExtension: {
'.js': '.mjs',
},
})
buildContext.hook('esm:complete', async () => {
})
buildContext.hook('esm:error', async error => {
})
buildContext.hook(CONSTANTS.ERROR, async error => {
})
buildContext.hook(CONSTANTS.BUILD_COMPLETE, async error => {
})
buildContext.hook(CONSTANTS.BUILD_ERROR, async error => {
})
buildContext.hook(CONSTANTS.WATCH_COMPLETE, async error => {
})
buildContext.hook(CONSTANTS.WATCH_ERROR, async error => {
})
await buildContext.watch()
await buildContext.build()
License
MIT