0.9.2 • Published 1 month ago

esbuild-multicontext v0.9.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

esbuild-multicontext

ComVer

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()

// Use the helper glob to find files and directories
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 () => {
  // context built completely
})

buildContext.hook('esm:error', async error => {
  // context failed with `error`
})

buildContext.hook(CONSTANTS.ERROR, async error => {
  // multi context build failed
})

buildContext.hook(CONSTANTS.BUILD_COMPLETE, async error => {
  // Overall build complete
})

buildContext.hook(CONSTANTS.BUILD_ERROR, async error => {
  // Overall build error
})

buildContext.hook(CONSTANTS.WATCH_COMPLETE, async error => {
  // Overall watch complete
})

buildContext.hook(CONSTANTS.WATCH_ERROR, async error => {
  // Overall watch error
})

// Watch each context and re-build on change
await buildContext.watch()

// Build each context and notify the respective hooks
await buildContext.build()

License

MIT

0.9.2

1 month ago

0.9.1

1 month ago

0.9.0-beta.1

1 month ago

0.9.0

1 month ago

0.9.0-beta.0

2 months ago

0.7.1

3 months ago

0.8.0

3 months ago

0.3.0

5 months ago

0.4.0

5 months ago

0.7.0

5 months ago

0.2.0

5 months ago

0.1.0

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago

0.0.1-beta.4

5 months ago

0.0.1-beta.3

5 months ago

0.0.1-beta.2

5 months ago

0.0.1-beta.1

5 months ago

0.0.0

5 months ago