effect-sugar-esbuild

raw JSON →
0.2.0 verified Fri May 01 auth: no javascript

An esbuild plugin that transforms Effect-TS gen block syntax (`const result = yield* effect`) into valid JavaScript. Version 0.2.0 supports esbuild >=0.17.0. It is part of the effect-sugar ecosystem alongside effect-sugar-vite and effect-sugar-tsc. Enables using Effect-TS generators without requiring ts-patch or Vite. Different from effect-sugar-tsc which uses ts-patch, this plugin integrates directly as an esbuild plugin for faster builds. Ships TypeScript type definitions. Released by clayroach on GitHub under MIT license.

error Error: esbuild: Must use import to load ES Module: /path/to/effect-sugar-esbuild
cause Attempting to require() an ESM-only package.
fix
Use import instead of require, or set "type": "module" in package.json.
error Error: [plugin: effect-sugar] The plugin must be called with effectSugarESBuild()
cause Passing the function reference instead of calling it.
fix
Use plugins: [effectSugarESBuild()] (with parentheses) in esbuild config.
breaking The package is pre-1.0.0 and may introduce breaking changes in minor versions.
fix Pin to exact version (e.g., effect-sugar-esbuild@0.2.0) to avoid unexpected breaks.
gotcha The plugin only works with esbuild >=0.17.0. Using older esbuild versions will cause errors.
fix Upgrade esbuild to >=0.17.0.
gotcha This plugin only transforms gen block syntax; it does NOT include the Effect-TS runtime. You must also install the main effect package.
fix Install effect (e.g., effect, @effect/core) separately.
npm install effect-sugar-esbuild
yarn add effect-sugar-esbuild
pnpm add effect-sugar-esbuild

Demonstrates adding the Effect-TS sugar plugin to esbuild for transforming gen blocks in both config file and programmatic usage.

// Install: npm install --save-dev effect-sugar-esbuild

// esbuild.config.js
import { effectSugarESBuild } from 'effect-sugar-esbuild';

export default {
  plugins: [effectSugarESBuild()],
  // ... other esbuild options
};

// Or programmatically:
import * as esbuild from 'esbuild';
import { effectSugarESBuild } from 'effect-sugar-esbuild';

await esbuild.build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outfile: 'dist/index.js',
  plugins: [effectSugarESBuild()],
});