esbuild-plugin-json-merge

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

esbuild plugin to merge multiple JSON sources (glob patterns or inline objects) into a single output file during the build process. Version 0.1.0 is stable with no recent updates; it uses deep merging via Object.assign by default and supports custom merge functions. Differentiators: seamless integration with esbuild's pipeline, supports globs and inline objects, optional custom merge logic. Ships TypeScript types with MIT license. Ideal for bundling manifest files or configuration JSONs.

error Error: Could not resolve 'esbuild-plugin-json-merge'
cause Package not installed or missing from node_modules.
fix
Run 'npm install esbuild-plugin-json-merge --save-dev'.
error TypeError: jsonMerge is not a function
cause Using default import in CJS without calling .default.
fix
Use 'const jsonMerge = require('esbuild-plugin-json-merge').default' or switch to ESM import.
error Error: [esbuild] Must use '--entry-names' or similar? No, this error arises from misconfiguration.
cause Plugin options incorrectly passed or missing required fields.
fix
Ensure entryPoints is an array of strings/objects and outfile is a string.
gotcha Default merge uses shallow Object.assign; nested objects overwrite instead of deep merge.
fix Provide a custom merge function, e.g., using default-composer or lodash.merge.
gotcha entryPoints accepts glob patterns; ensure globs match expected files to avoid missing data.
fix Test glob patterns with glob package directly if issues arise.
breaking Library switched to ESM-only? Check usage if using older Node versions without ESM support.
fix Use dynamic import() in Node <12, or configure bundler for CommonJS.
gotcha outfile path is relative to esbuild's outdir; not the project root by default.
fix Set outfile relative to outdir, or adjust esbuild's working directory.
deprecated Version 0.1.0 has no known deprecations yet; this is a placeholder for future.
fix Monitor releases for updates.
npm install esbuild-plugin-json-merge
yarn add esbuild-plugin-json-merge
pnpm add esbuild-plugin-json-merge

Compiles an esbuild build that merges a file and inline object into a single JSON output.

import esbuild from 'esbuild';
import jsonMerge from 'esbuild-plugin-json-merge';

const { version, name, description } = { version: '1.0.0', name: 'my-app', description: 'Example app' };

await esbuild.build({
  entryPoints: ['src/index.js'],
  outdir: 'dist',
  plugins: [
    jsonMerge({
      entryPoints: ['src/manifest.json', { version, name, description }],
      outfile: 'manifest.json',
    }),
  ],
});