An esbuild plugin (v2.1.0) for generating modules at bundle time, allowing dynamic code injection during builds. Part of the codegen-js monorepo, it provides a core library (`codegen-lib`) and loaders for esbuild, webpack, parcel, and bun. Supports both ESM and CJS output. Key differentiator: code generation at bundle time rather than pre-build scripts, enabling type-safe dynamic imports and real-time code generation based on build context. Released monthly with active maintenance.
npm install esbuild-codegen-pluginNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use esbuild-codegen-plugin to inject a generated module (build-time constant) during esbuild bundling.
Switch to ESM imports: import { esbuildCodegenPlugin } from 'esbuild-codegen-plugin'.Use paths like './my-module.ts' instead of '/absolute/path/my-module.ts'.
Use unique paths or namespaced prefixes for generated modules.
Replace generate(config)(esbuildConfig) with esbuildCodegenPlugin(config) in plugin array.
Run npm install esbuild-codegen-plugin --save-dev
Use import { esbuildCodegenPlugin } from 'esbuild-codegen-plugin' (ESM only).Call the function: esbuildCodegenPlugin({...}) and pass its return value to plugins array.