cogs-transformer-esbuild

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

An esbuild transformer for the Cogs build system. This package integrates esbuild bundling/minification into Cogs pipelines. It is a thin wrapper around esbuild's transform API, optimized for speed and simplicity. The current version is 1.0.10 with no recent updates (likely stable). Unlike other Cogs transformers (ts, babel), this one leverages esbuild's native speed and TypeScript/JSX support. It is designed for projects already using Cogs.

error Error: Cannot find module 'cogs-transformer-esbuild'
cause Package not installed or not in node_modules.
fix
Run npm install cogs-transformer-esbuild --save-dev
error TypeError: transformer is not a function
cause Using named import instead of default import.
fix
Use import cogsTransformerEsbuild from 'cogs-transformer-esbuild' (default import).
error Error: Unknown option: jsxImportSource
cause The transformer does not support esbuild's jsxImportSource option.
fix
Remove jsxImportSource; use jsxFactory and jsxFragment instead.
gotcha Transformer options must be an object literal; do not pass a function.
fix Pass a plain object as argument to the transformer factory.
gotcha Cogs version compatibility: this transformer requires Cogs >=3.x due to ES module support.
fix Ensure Cogs is updated to version 3 or higher.
gotcha The transformer does not support esbuild's bundle option directly; bundle only works via Cogs plugin cascade.
fix Use Cogs entry points and plugins to achieve bundling.
gotcha JSX runtime automatic mode is not supported; use classic or explicit pragma.
fix Set jsx: 'preserve' or use jsxFactory/jsxFragment options.
deprecated The `platform` option in esbuild options is deprecated for this transformer; use Cogs target config.
fix Remove platform option; configure target platform via Cogs settings.
npm install cogs-transformer-esbuild
yarn add cogs-transformer-esbuild
pnpm add cogs-transformer-esbuild

Shows how to configure the esbuild transformer in a Cogs file with common options.

// cogsfile.js
import cogsTransformerEsbuild from 'cogs-transformer-esbuild';

export default {
  // other Cogs config
  transformers: [
    cogsTransformerEsbuild({
      target: 'es2020',
      minify: true,
      jsxFactory: 'h',
      jsxFragment: 'Fragment',
    }),
  ],
};